@@ -73,6 +73,7 @@ protected function download($version)
73
73
* Unzips the package zip to the current directory
74
74
*
75
75
* @param $package
76
+ * @throws \Exception
76
77
*/
77
78
protected function unzip ($ package )
78
79
{
@@ -131,14 +132,50 @@ protected function retrieveFromCache($version)
131
132
{
132
133
$ version = 'modx- ' . str_replace ('modx- ' , '' , $ version );
133
134
134
-
135
135
$ path = GITIFY_CACHE_DIR . $ version ;
136
136
137
137
if (!file_exists ($ path ) || !is_dir ($ path )) {
138
138
$ this ->download ($ version );
139
139
}
140
140
141
- exec ("cp -r $ path/* ./ " );
141
+ // Handle potential custom paths on upgrade
142
+ if ($ this ->isUpgrade ) {
143
+ require_once './config.core.php ' ;
144
+ if (MODX_CORE_PATH ) {
145
+ require_once MODX_CORE_PATH . 'config/config.inc.php ' ;
146
+ // Need to avoid the easier route with rsync as it may not be installed
147
+ $ paths = [
148
+ 'core ' => MODX_CORE_PATH ,
149
+ 'connectors ' => MODX_CONNECTORS_PATH ,
150
+ 'manager ' => MODX_MANAGER_PATH
151
+ ];
152
+ foreach ($ paths as $ k => $ customPath ) {
153
+ // Throw out default config files
154
+ if (file_exists ("$ path/ $ k/config.core.php " )) {
155
+ unlink ("$ path/ $ k/config.core.php " );
156
+ }
157
+ // Copy each dir to path specified in config file then remove that dir from source
158
+ exec ("cp -r $ path/ $ k/* $ customPath " );
159
+ exec ("rm -rf $ path/ $ k " );
160
+ }
161
+
162
+ unlink ("$ path/config.core.php " );
163
+
164
+ // Now copy remaining contents
165
+ exec ("cp -r $ path/* ./ " );
166
+
167
+ // Hard wipe cache
168
+ if (is_dir (MODX_CORE_PATH . 'cache/ ' )) {
169
+ exec ('rm -rf ' . MODX_CORE_PATH . 'cache/* ' );
170
+ }
171
+
172
+ // Re-extract package to source dir, so it's ready for another run.
173
+ $ this ->unzip ($ path . '.zip ' );
174
+ }
175
+ }
176
+ else {
177
+ exec ("cp -r $ path/* ./ " );
178
+ }
142
179
}
143
180
144
181
/**
0 commit comments