Skip to content

Commit d7642f2

Browse files
committed
#1.12.1 Minor update to Core_UpdateManager: Added event core:onFetchSoftwareUpdateFiles. Updated PclZip to 2.8.2
1 parent f478678 commit d7642f2

File tree

4 files changed

+1864
-1904
lines changed

4 files changed

+1864
-1904
lines changed

classes/core_updatemanager.php

Lines changed: 74 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ protected function get_blocked_update_modules(){
112112
$ignored = Backend::$events->fire_event(array('name' => 'core:onGetBlockedUpdateModules', 'type' => 'filter'), array(
113113
'modules' => $ignored,
114114
));
115-
traceLog( $ignored['modules']);
116115
return $ignored['modules'];
117116
}
118117

@@ -125,9 +124,9 @@ protected function get_hash()
125124
$framework = Phpr_SecurityFramework::create();
126125
return $framework->decrypt(base64_decode($hash));
127126
}
128-
129-
public function request_update_list($hash = null, $force = false)
130-
{
127+
128+
public function request_lemonstand_update_list($hash = null, $force = false){
129+
131130
if (!$force && Phpr::$config->get('FREEZE_UPDATES'))
132131
throw new Exception("We are sorry, updates were blocked by the system administrator.");
133132

@@ -143,10 +142,20 @@ public function request_update_list($hash = null, $force = false)
143142
$response = $this->request_server_data('get_update_list/'.$hash, $fields, $force);
144143
if (!isset($response['data']))
145144
throw new Phpr_ApplicationException('Invalid server response.');
146-
145+
147146
if (!count($response['data']))
148147
Db_ModuleParameters::set('backend', 'ls_updates_available', 0);
149148

149+
return $response;
150+
}
151+
152+
public function request_update_list()
153+
{
154+
if (Phpr::$config->get('FREEZE_UPDATES'))
155+
throw new Exception("We are sorry, updates were blocked by the system administrator.");
156+
157+
$response = $this->request_lemonstand_update_list();
158+
150159
$response = Backend::$events->fire_event(array('name' => 'core:onAfterRequestUpdateList', 'type' => 'filter'), array(
151160
'update_list' => $response,
152161
));
@@ -161,82 +170,90 @@ public function update_application($cli_mode = false, $force = false)
161170
if (Phpr::$config->get('FREEZE_UPDATES'))
162171
throw new Exception("We are sorry, updates were blocked by the system administrator.");
163172

164-
if (!$force)
165-
{
166-
$update_data = $this->request_update_list();
167-
$update_list = $update_data['data'];
168-
$fields = array(
169-
'modules'=>serialize(array_keys($update_list)),
170-
'disabled'=>serialize($this->get_blocked_update_modules())
171-
);
172-
} else
173-
{
173+
if (!is_writable(PATH_APP.'/temp') || !is_writable(PATH_APP.'/modules') || !is_writable(PATH_APP.'/phproad'))
174+
throw new Exception('An install directory in '.PATH_APP.' (/temp , /modules, /phproad) is not writable for PHP.');
175+
176+
if(!$force){
177+
$update_list = $this->request_lemonstand_update_list();
178+
$versions = $update_list['data'];
179+
} else {
174180
$versions = $this->get_module_versions();
181+
}
182+
183+
if(array($versions)){
184+
//do lemonstand update downloads
175185
$fields = array(
176186
'modules'=>serialize(array_keys($versions)),
177187
'disabled'=>serialize($this->get_blocked_update_modules())
178188
);
179-
}
180-
181-
if (!is_writable(PATH_APP) || !is_writable(PATH_APP.'/modules') || !is_writable(PATH_APP.'/phproad'))
182-
throw new Exception('The LemonStand directory ('.PATH_APP.') is not writable for PHP.');
183189

184-
$hash = $this->get_hash();
185-
$result = $this->request_server_data('get_update_hashes/'.$hash, $fields);
186-
$file_hashes = $result['data'];
190+
$hash = $this->get_hash();
191+
$result = $this->request_server_data('get_update_hashes/'.$hash, $fields);
192+
$file_hashes = $result['data'];
187193

188-
if (!is_array($file_hashes))
189-
throw new Exception("Invalid server response");
194+
if (!is_array($file_hashes))
195+
throw new Exception("Invalid server response");
190196

191-
$tmp_path = PATH_APP.'/temp';
192-
if (!is_writable($tmp_path))
193-
throw new Exception("Cannot create temporary file. Path is not writable: $tmp_path");
197+
$tmp_path = PATH_APP.'/temp';
198+
if (!is_writable($tmp_path))
199+
throw new Exception("Cannot create temporary file. Path is not writable: $tmp_path");
194200

195-
$files = array();
196-
try
197-
{
198-
foreach ($file_hashes as $code=>$file_hash)
199-
{
200-
$tmp_file = $tmp_path.'/'.$code.'.arc';
201-
$result = $this->request_server_data('get_update_file/'.$hash.'/'.$code);
201+
$ls_files = array();
202+
try {
203+
foreach ( $file_hashes as $code => $file_hash ) {
204+
$tmp_file = $tmp_path . '/' . $code . '.arc';
205+
$result = $this->request_server_data( 'get_update_file/' . $hash . '/' . $code );
202206

203-
$tmp_save_result = false;
204-
try
205-
{
206-
$tmp_save_result = @file_put_contents($tmp_file, $result['data']);
207-
} catch (Exception $ex)
208-
{
209-
throw new Exception("Error creating temporary file in ".$tmp_path);
210-
}
207+
$tmp_save_result = false;
208+
try {
209+
$tmp_save_result = @file_put_contents( $tmp_file, $result['data'] );
210+
} catch ( Exception $ex ) {
211+
throw new Exception( "Error creating temporary file in " . $tmp_path );
212+
}
211213

212-
$files[] = $tmp_file;
214+
$ls_files[] = $tmp_file;
213215

214-
if (!$tmp_save_result)
215-
throw new Exception("Error creating temporary file in ".$tmp_path);
216+
if ( !$tmp_save_result ) {
217+
throw new Exception( "Error creating temporary file in " . $tmp_path );
218+
}
216219

217-
$downloaded_hash = md5_file($tmp_file);
218-
if ($downloaded_hash != $file_hash)
219-
throw new Exception("Downloaded archive is corrupted. Please try again.");
220+
$downloaded_hash = md5_file( $tmp_file );
221+
if ( $downloaded_hash != $file_hash ) {
222+
throw new Exception( "Downloaded archive is corrupted. Please try again." );
223+
}
224+
}
225+
} catch (Exception $ex){
226+
$this->update_cleanup($ls_files);
227+
throw $ex;
228+
}
220229
}
221230

231+
//allow for other modules to provide updates
232+
$files = Backend::$events->fire_event(array('name' => 'core:onFetchSoftwareUpdateFiles', 'type' => 'filter'), array(
233+
'files' => $ls_files,
234+
));
235+
$files = $files['files'];
236+
237+
try{
222238
Backend::$events->fireEvent('core:onBeforeSoftwareUpdate');
223-
224-
foreach ($files as $file)
239+
240+
foreach ($files as $file) {
225241
Core_ZipHelper::unzip(PATH_APP, $file, $cli_mode);
242+
}
226243

227244
$this->update_cleanup($files);
228-
245+
229246
Db_UpdateManager::update();
230247

231248
Db_ModuleParameters::set('backend', 'ls_updates_available', 0);
232249

233250
Backend::$events->fireEvent('core:onAfterSoftwareUpdate');
234-
} catch (Exception $ex)
235-
{
251+
} catch (Exception $ex) {
236252
$this->update_cleanup($files);
237-
238253
throw $ex;
239254
}
255+
256+
240257
}
241258

242259
protected function update_cleanup($files)
@@ -278,7 +295,7 @@ public function get_updates_flag()
278295
{
279296
try
280297
{
281-
$update_data = Core_UpdateManager::create()->request_update_list();
298+
$update_data = Core_UpdateManager::create()->request_lemonstand_update_list();
282299
$updates = $update_data['data'];
283300

284301
Db_ModuleParameters::set('backend', 'ls_updates_available', count($updates));
@@ -317,7 +334,7 @@ public function cli_update($force = false)
317334

318335
try
319336
{
320-
$update_data = $this->request_update_list();
337+
$update_data = $this->request_lemonstand_update_list();
321338
$update_list = $update_data['data'];
322339

323340
if (!count($update_list))
@@ -411,7 +428,7 @@ public function set_license_info($data)
411428
$framework = Phpr_SecurityFramework::create();
412429
$new_hash = base64_encode($framework->encrypt(md5($serial_number.$holder_name)));
413430

414-
$this->request_update_list(md5($serial_number.$holder_name), true);
431+
$this->request_lemonstand_update_list(md5($serial_number.$holder_name), true);
415432

416433
Db_ModuleParameters::set('core', 'hash', $new_hash);
417434
Db_ModuleParameters::set('core', 'license_key', $new_license_key);

helpers/core_ziphelper.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,20 @@ class Core_ZipHelper
88
public static $_chmod_error = false;
99

1010
protected static $_initialized = false;
11-
11+
12+
public static function findFile($file, $archivePath){
13+
self::initZip();
14+
$archive = new PclZip($archivePath);
15+
16+
foreach($archive->listContent() as $key => $file_info){
17+
if(strstr($file_info['filename'],$file)){
18+
return $file_info;
19+
}
20+
21+
}
22+
return false;
23+
}
24+
1225
public static function zipFile($file, $archivePath)
1326
{
1427
self::initZip();
@@ -66,7 +79,7 @@ public static function zipFiles($basePath, $files, $archivePath)
6679
* images/* - will exclude all folders and files from images directory
6780
* images/[files] - file exclude all files from images directory and its subdirectories
6881
*/
69-
public static function zipDirectory($path, $archivePath, $exceptions = array(), $archive = null)
82+
public static function zipDirectory($path, $archivePath, $exceptions = array(), $archive = null, $add_path = null)
7083
{
7184
self::initZip();
7285
chdir($path);
@@ -86,7 +99,7 @@ public static function zipDirectory($path, $archivePath, $exceptions = array(),
8699
if ( $entry == '.' || $entry == '..' )
87100
continue;
88101

89-
$archive->add($entry, PCLZIP_CB_PRE_ADD, 'zip_helper_pre_add');
102+
$archive->add($entry, PCLZIP_CB_PRE_ADD, 'zip_helper_pre_add',PCLZIP_OPT_ADD_PATH, $add_path);
90103
}
91104

92105
$d->close();

0 commit comments

Comments
 (0)