author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /backend/php/src/setup/setup_library/upgrade.php | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'backend/php/src/setup/setup_library/upgrade.php') (more/less context) (ignore whitespace changes)
-rw-r--r-- | backend/php/src/setup/setup_library/upgrade.php | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/backend/php/src/setup/setup_library/upgrade.php b/backend/php/src/setup/setup_library/upgrade.php new file mode 100644 index 0000000..122da58 --- a/dev/null +++ b/backend/php/src/setup/setup_library/upgrade.php | |||
@@ -0,0 +1,140 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * @author Joel Wan & Mark Slemko. Designs by Jonathan Easton | ||
4 | * @link http://www.phpobjectgenerator.com | ||
5 | * @copyright Offered under the BSD license | ||
6 | * | ||
7 | * This upgrade file does the following: | ||
8 | * 1. Checks if there is a new version of POG | ||
9 | * 2. If there is, it reads generates newer versions of all objects in the object directory, | ||
10 | * zip then and present them to the user to 'download' | ||
11 | */ | ||
12 | ini_set("max_execution_time", 0); | ||
13 | include_once "../../configuration.php"; | ||
14 | include_once "class.zipfile.php"; | ||
15 | include_once "setup_misc.php"; | ||
16 | |||
17 | /** | ||
18 | * Connects to POG SOAP server defined in configuration.php and | ||
19 | * generates new versions of all objects detected in /objects/ dir. | ||
20 | * All upgraded objects are then zipped and presented to user. | ||
21 | * | ||
22 | * @param string $path | ||
23 | */ | ||
24 | function UpdateAllObjects($path) | ||
25 | { | ||
26 | $dir = opendir($path); | ||
27 | $objects = array(); | ||
28 | while(($file = readdir($dir)) !== false) | ||
29 | { | ||
30 | if(strlen($file) > 4 && substr(strtolower($file), strlen($file) - 4) === '.php' && !is_dir($file) && $file != "class.database.php" && $file != "configuration.php" && $file != "setup.php" && $file != "class.pog_base.php") | ||
31 | { | ||
32 | $objects[] = $file; | ||
33 | } | ||
34 | } | ||
35 | closedir($dir); | ||
36 | $i = 0; | ||
37 | foreach($objects as $object) | ||
38 | { | ||
39 | $content = file_get_contents($path."/".$object); | ||
40 | $contentParts = split("<b>",$content); | ||
41 | if (isset($contentParts[1])) | ||
42 | { | ||
43 | $contentParts2 = split("</b>",$contentParts[1]); | ||
44 | } | ||
45 | if (isset($contentParts2[0])) | ||
46 | { | ||
47 | $className = trim($contentParts2[0]); | ||
48 | } | ||
49 | if (isset($className)) | ||
50 | { | ||
51 | eval ('include_once("../../objects/class.'.strtolower($className).'.php");'); | ||
52 | $instance = new $className(); | ||
53 | if (!TestIsMapping($instance)) | ||
54 | { | ||
55 | $objectNameList[] = $className; | ||
56 | |||
57 | $linkParts1 = split("\*\/", $contentParts[1]); | ||
58 | $linkParts2 = split("\@link", $linkParts1[0]); | ||
59 | $link = $linkParts2[1]; | ||
60 | $options = false; | ||
61 | if ($GLOBALS['configuration']['proxy_host'] != false && | ||
62 | $GLOBALS['configuration']['proxy_port'] != false && | ||
63 | $GLOBALS['configuration']['proxy_username'] != false && | ||
64 | $GLOBALS['configuration']['proxy_password'] != false) | ||
65 | { | ||
66 | $options = array( | ||
67 | 'proxy_host' => $GLOBALS['configuration']['proxy_host'], | ||
68 | 'proxy_port' => $GLOBALS['configuration']['proxy_port'], | ||
69 | 'proxy_login' => $GLOBALS['configuration']['proxy_username'], | ||
70 | 'proxy_password' => $GLOBALS['configuration']['proxy_password'] | ||
71 | ); | ||
72 | } | ||
73 | $client = new SoapClient( | ||
74 | $GLOBALS['configuration']['soap'], | ||
75 | $options) ; | ||
76 | if ($i == 0) | ||
77 | { | ||
78 | $package = unserialize($client->GeneratePackageFromLink($link)); | ||
79 | } | ||
80 | else | ||
81 | { | ||
82 | $objectString = $client->GenerateObjectFromLink($link); | ||
83 | $package["objects"]["class.".strtolower($className).".php"] = $objectString; | ||
84 | } | ||
85 | } | ||
86 | } | ||
87 | $i++; | ||
88 | } | ||
89 | |||
90 | |||
91 | //upgrade mapping classes if any | ||
92 | foreach ($objectNameList as $objectName) | ||
93 | { | ||
94 | $instance = new $objectName(); | ||
95 | foreach ($instance->pog_attribute_type as $key => $attribute_type) | ||
96 | { | ||
97 | if ($attribute_type['db_attributes'][1] == "JOIN") | ||
98 | { | ||
99 | $mappingString = $client->GenerateMapping($objectName, $key, (isset($GLOBALS['configuration']['pdoDriver']) ? 'php5.1' :'php5'), (isset($GLOBALS['configuration']['pdoDriver']) ? 'pdo' :'pog'), (isset($GLOBALS['configuration']['pdoDriver']) ? 'mysql' :'')); | ||
100 | $package["objects"]['class.'.strtolower(MappingName($objectName, $key)).'.php'] = $mappingString; | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | $zipfile = new createZip(); | ||
106 | $zipfile -> addPOGPackage($package); | ||
107 | $zipfile -> forceDownload("pog.".time().".zip"); | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * Checks if POG generator has been updated | ||
112 | * | ||
113 | * @return unknown | ||
114 | */ | ||
115 | function UpdateAvailable() | ||
116 | { | ||
117 | $client = new SoapClient($GLOBALS['configuration']['soap']); | ||
118 | $generatorVersion = base64_decode($client -> GetGeneratorVersion()); | ||
119 | if ($generatorVersion != $GLOBALS['configuration']['versionNumber'].$GLOBALS['configuration']['revisionNumber']) | ||
120 | { | ||
121 | return true; | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | return false; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | if (UpdateAvailable()) | ||
130 | { | ||
131 | UpdateAllObjects("../../objects/"); | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | echo "<script> | ||
136 | alert('All POG objects are already up to date'); | ||
137 | window.close(); | ||
138 | </script>"; | ||
139 | } | ||
140 | ?> \ No newline at end of file | ||