Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of git://github.com/osCommerce/oscommerce

  • Loading branch information...
commit 6bfe84a5f6cf272d5626bdb0cb7fe41f7c712b18 2 parents 9b9023b + bcaa981
@tgely authored
View
142 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/applyPackage.php
@@ -10,40 +10,162 @@
use \Phar;
use \RecursiveIteratorIterator;
+ use osCommerce\OM\Core\DateTime;
+ use osCommerce\OM\Core\DirectoryListing;
use osCommerce\OM\Core\OSCOM;
class applyPackage {
+ protected static $_to_version;
+
public static function execute() {
$phar_can_open = true;
+ $pro_hart = array();
+
try {
$phar = new Phar(OSCOM::BASE_DIRECTORY . 'Work/CoreUpdate/update.phar');
+ $meta = $phar->getMetadata();
+
+ self::$_to_version = $meta['version_to'];
+
+// reset the log
+ if ( file_exists(OSCOM::BASE_DIRECTORY . 'Work/Logs/update-' . self::$_to_version . '.txt') && is_writable(OSCOM::BASE_DIRECTORY . 'Work/Logs/update-' . self::$_to_version . '.txt') ) {
+ unlink(OSCOM::BASE_DIRECTORY . 'Work/Logs/update-' . self::$_to_version . '.txt');
+ }
+
+ self::log('##### UPDATE TO ' . self::$_to_version . ' STARTED');
+
+// first delete files before extracting new files
+ if ( isset($meta['delete']) ) {
+ foreach ( $meta['delete'] as $file ) {
+ $directory = (substr($file, 0, 14) == 'osCommerce/OM/' ? realpath(OSCOM::BASE_DIRECTORY . '../../') : realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../')) . '/';
+
+ if ( file_exists($directory . $file) ) {
+ if ( is_dir($directory . $file) ) {
+ if ( rename($directory . $file, $directory . dirname($file) . '/.CU_' . basename($file)) ) {
+ $pro_hart[] = array('type' => 'directory',
+ 'where' => $directory,
+ 'path' => dirname($file) . '/.CU_' . basename($file),
+ 'log' => true);
+ }
+ } else {
+ if ( rename($directory . $file, $directory . dirname($file) . '/.CU_' . basename($file)) ) {
+ $pro_hart[] = array('type' => 'file',
+ 'where' => $directory,
+ 'path' => dirname($file) . '/.CU_' . basename($file),
+ 'log' => true);
+ }
+ }
+ }
+ }
+ }
+
// loop through each file individually as extractTo() does not work with
// directories (see http://bugs.php.net/bug.php?id=54289)
foreach ( new RecursiveIteratorIterator($phar) as $iteration ) {
if ( ($pos = strpos($iteration->getPathName(), 'update.phar')) !== false ) {
$file = substr($iteration->getPathName(), $pos+12);
- if ( substr($file, 0, 14) == 'osCommerce/OM/' ) {
- $phar->extractTo(realpath(OSCOM::BASE_DIRECTORY . '../../'), $file, true);
- } elseif ( substr($file, 0, 7) == 'public/' ) {
- $phar->extractTo(realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../'), $file, true);
+ $directory = (substr($file, 0, 14) == 'osCommerce/OM/' ? realpath(OSCOM::BASE_DIRECTORY . '../../') : realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../')) . '/';
+
+ if ( file_exists($directory . $file) ) {
+ if ( rename($directory . $file, $directory . dirname($file) . '/.CU_' . basename($file)) ) {
+ $pro_hart[] = array('type' => 'file',
+ 'where' => $directory,
+ 'path' => dirname($file) . '/.CU_' . basename($file),
+ 'log' => false);
+ }
+ }
+
+ if ( $phar->extractTo($directory, $file, true) ) {
+ self::log('Extracted: ' . $file);
+ } else {
+ self::log('*** Could Not Extract: ' . $file);
+ }
+ }
+ }
+
+ self::log('##### CLEANUP');
+
+ foreach ( array_reverse($pro_hart, true) as $mess ) {
+ if ( $mess['type'] == 'directory' ) {
+ if ( self::rmdir_r($mess['where'] . $mess['path']) ) {
+ if ( $mess['log'] === true ) {
+ self::log('Deleted: ' . str_replace('/.CU_', '/', $mess['path']));
+ }
+ } else {
+ if ( $mess['log'] === true ) {
+ self::log('*** Could Not Delete: ' . str_replace('/.CU_', '/', $mess['path']));
+ }
+ }
+ } else {
+ if ( unlink($mess['where'] . $mess['path']) ) {
+ if ( $mess['log'] === true ) {
+ self::log('Deleted: ' . str_replace('/.CU_', '/', $mess['path']));
+ }
+ } else {
+ if ( $mess['log'] === true ) {
+ self::log('*** Could Not Delete: ' . str_replace('/.CU_', '/', $mess['path']));
+ }
}
}
}
+
+ self::log('##### UPDATE TO ' . self::$_to_version . ' COMPLETED');
} catch ( \Exception $e ) {
-// ignore when file permissions from the phar archive cannot be set to the
-// extracted files
-// HPDL look for a more elegant solution
- if ( strpos($e->getMessage(), 'setting file permissions failed') === false ) {
- $phar_can_open = false;
+ $phar_can_open = false;
+
+ self::log('##### ERROR: ' . $e->getMessage());
+
+ self::log('##### REVERTING');
+
+ foreach ( array_reverse($pro_hart, true) as $mess ) {
+ if ( $mess['type'] == 'directory' ) {
+ if ( file_exists($mess['where'] . str_replace('/.CU_', '/', $mess['path'])) ) {
+ self::rmdir_r($mess['where'] . str_replace('/.CU_', '/', $mess['path']));
+ }
+ } else {
+ if ( file_exists($mess['where'] . str_replace('/.CU_', '/', $mess['path'])) ) {
+ unlink($mess['where'] . str_replace('/.CU_', '/', $mess['path']));
+ }
+ }
- trigger_error($e->getMessage());
+ if ( file_exists($mess['where'] . $mess['path']) ) {
+ rename($mess['where'] . $mess['path'], $mess['where'] . str_replace('/.CU_', '/', $mess['path']));
+ }
+
+ self::log('Reverted: ' . str_replace('/.CU_', '/', $mess['path']));
}
+
+ self::log('##### REVERTING COMPLETED');
+ self::log('##### UPDATE TO ' . self::$_to_version . ' FAILED');
+
+ trigger_error($e->getMessage());
+ trigger_error('Please review the update log at: ' . OSCOM::BASE_DIRECTORY . 'Work/Logs/update-' . self::$_to_version . '.txt');
}
return $phar_can_open;
}
+
+ protected static function log($message) {
+ if ( is_writable(OSCOM::BASE_DIRECTORY . 'Work/Logs') ) {
+ file_put_contents(OSCOM::BASE_DIRECTORY . 'Work/Logs/update-' . self::$_to_version . '.txt', '[' . DateTime::getNow('d-M-Y H:i:s') . '] ' . $message . "\n", FILE_APPEND);
+ }
+ }
+
+ protected static function rmdir_r($dir) {
+ foreach ( scandir($dir) as $file ) {
+ if ( !in_array($file, array('.', '..')) ) {
+ if ( is_dir($dir . '/' . $file) ) {
+ self::rmdir_r($dir . '/' . $file);
+ } else {
+ unlink($dir . '/' . $file);
+ }
+ }
+ }
+
+ return rmdir($dir);
+ }
}
?>
View
2  osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/findPackageContents.php
@@ -15,7 +15,7 @@ public static function execute($search) {
$result = CoreUpdate::getPackageContents();
foreach ( $result['entries'] as $k => $v ) {
- if ( strpos($v['name'], $search) === false ) {
+ if ( stripos($v['name'], $search) === false ) {
unset($result['entries'][$k]);
}
}
View
79 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/getPackageContents.php
@@ -10,6 +10,7 @@
use \Phar;
use \RecursiveIteratorIterator;
+ use osCommerce\OM\Core\DirectoryListing;
use osCommerce\OM\Core\OSCOM;
class getPackageContents {
@@ -41,23 +42,95 @@ public static function execute() {
foreach ( $update_pkg as $file ) {
if ( substr($file, 0, 14) == 'osCommerce/OM/' ) {
+ $custom = false;
+
+ if ( substr($file, 14, 5) == 'Core/' ) {
+ $custom = file_exists(realpath(OSCOM::BASE_DIRECTORY . '../../') . '/osCommerce/OM/Custom/' . substr($file, 19));
+ }
+
$result['entries'][] = array('key' => $counter,
'name' => $file,
- 'exists' => file_exists(realpath(OSCOM::BASE_DIRECTORY . '/../../') . '/' . $file),
- 'writable' => self::isWritable(realpath(OSCOM::BASE_DIRECTORY . '/../../') . '/' . $file));
+ 'exists' => file_exists(realpath(OSCOM::BASE_DIRECTORY . '../../') . '/' . $file),
+ 'writable' => self::isWritable(realpath(OSCOM::BASE_DIRECTORY . '../../') . '/' . $file) && self::isWritable(realpath(OSCOM::BASE_DIRECTORY . '../../') . '/' . dirname($file)),
+ 'custom' => $custom,
+ 'to_delete' => false);
$counter++;
} elseif ( substr($file, 0, 7) == 'public/' ) {
$result['entries'][] = array('key' => $counter,
'name' => $file,
'exists' => file_exists(realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../') . '/' . $file),
- 'writable' => self::isWritable(realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../') . '/' . $file));
+ 'writable' => self::isWritable(realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../') . '/' . $file) && self::isWritable(realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../') . '/' . dirname($file)),
+ 'custom' => false,
+ 'to_delete' => false);
$counter++;
}
}
}
+ $meta = $phar->getMetadata();
+
+ if ( isset($meta['delete']) ) {
+ $files = array();
+
+ foreach ( $meta['delete'] as $file ) {
+ if ( substr($file, 0, 14) == 'osCommerce/OM/' ) {
+ if ( file_exists(realpath(OSCOM::BASE_DIRECTORY . '../../') . '/' . $file) ) {
+ if ( is_dir(realpath(OSCOM::BASE_DIRECTORY . '../../') . '/' . $file) ) {
+ $DL = new DirectoryListing(realpath(OSCOM::BASE_DIRECTORY . '../../') . '/' . $file);
+ $DL->setRecursive(true);
+ $DL->setAddDirectoryToFilename(true);
+ $DL->setIncludeDirectories(false);
+
+ foreach ( $DL->getFiles() as $f ) {
+ $files[] = $file . '/' . $f['name'];
+ }
+ } else {
+ $files[] = $file;
+ }
+ }
+ } elseif ( substr($file, 0, 7) == 'public/' ) {
+ if ( file_exists(realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../') . '/' . $file) ) {
+ if ( is_dir(realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../') . '/' . $file) ) {
+ $DL = new DirectoryListing(realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../') . '/' . $file);
+ $DL->setRecursive(true);
+ $DL->setAddDirectoryToFilename(true);
+ $DL->setIncludeDirectories(false);
+
+ foreach ( $DL->getFiles() as $f ) {
+ $files[] = $file . '/' . $f['name'];
+ }
+ } else {
+ $files[] = $file;
+ }
+ }
+ }
+ }
+
+ natcasesort($files);
+
+ foreach ( $files as $d ) {
+ $writable = false;
+ $custom = false;
+
+ if ( substr($d, 0, 14) == 'osCommerce/OM/' ) {
+ $writable = self::isWritable(realpath(OSCOM::BASE_DIRECTORY . '../../') . '/' . $d) && self::isWritable(realpath(OSCOM::BASE_DIRECTORY . '../../') . '/' . dirname($d));
+ } elseif ( substr($d, 0, 7) == 'public/' ) {
+ $writable = self::isWritable(realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../') . '/' . $d) && self::isWritable(realpath(OSCOM::getConfig('dir_fs_public', 'OSCOM') . '../') . '/' . dirname($d));
+ }
+
+ $result['entries'][] = array('key' => $counter,
+ 'name' => $d,
+ 'exists' => true,
+ 'writable' => $writable,
+ 'custom' => $custom,
+ 'to_delete' => true);
+
+ $counter++;
+ }
+ }
+
$result['total'] = count($result['entries']);
return $result;
View
11 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/pages/main.php
@@ -109,5 +109,16 @@ function feedDataTable(data) {
rowCounter++;
}
+
+ if ( (rowCounter == 0) && (moduleParams['search'] == '') ) {
+ var newRow = $('#' + dataTableName)[0].tBodies[0].insertRow(rowCounter);
+ newRow.id = 'row0';
+
+ $('#row0').hover( function() { $(this).addClass('mouseOver'); }, function() { $(this).removeClass('mouseOver'); }).css('cursor', 'pointer');
+
+ var newCell = newRow.insertCell(0);
+ newCell.colSpan = 3;
+ newCell.innerHTML = '<?php echo HTML::icon('tick.png') . ' '; ?>' + htmlSpecialChars("<?php echo OSCOM::getDef('up_to_date'); ?>");
+ }
}
</script>
View
19 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/pages/package_contents.php
@@ -34,8 +34,8 @@
<thead>
<tr>
<th><?php echo OSCOM::getDef('table_heading_files'); ?></th>
- <th width="150"><?php echo OSCOM::getDef('table_heading_file_replace'); ?></th>
- <th width="150"><?php echo OSCOM::getDef('table_heading_file_writable'); ?></th>
+ <th width="100"><?php echo OSCOM::getDef('table_heading_file_writable'); ?></th>
+ <th width="100"><?php echo OSCOM::getDef('table_heading_file_custom'); ?></th>
</tr>
</thead>
<tfoot>
@@ -48,7 +48,7 @@
</table>
<div style="padding: 2px; min-height: 16px;">
- <span id="dataTableLegend"></span>
+ <span id="dataTableLegend"><?php echo '<b>' . OSCOM::getDef('table_action_legend') . '</b> <span style="background-color: #ceffc8; padding: 1px 10px 1px 10px;">' . OSCOM::getDef('legend_new') . '</span> <span style="background-color: #ffebc8; padding: 1px 10px 1px 10px;">' . OSCOM::getDef('legend_modified') . '</span> <span style="background-color: #ffc8c8; padding: 1px 10px 1px 10px;">' . OSCOM::getDef('legend_to_delete') . '</span>'; ?></span>
<span id="batchPullDownMenu"></span>
</div>
@@ -69,6 +69,7 @@
var checkboxTickedIcon = '<?php echo HTML::icon('checkbox_ticked.gif'); ?>';
var checkboxCrossedIcon = '<?php echo HTML::icon('checkbox_crossed.gif'); ?>';
+ var checkboxIcon = '<?php echo HTML::icon('checkbox.gif'); ?>';
var osC_DataTable = new osC_DataTable();
osC_DataTable.load();
@@ -88,13 +89,21 @@ function feedDataTable(data) {
newCell.innerHTML = htmlSpecialChars(record.name);
var newCell = newRow.insertCell(1);
- newCell.innerHTML = record.exists == true ? checkboxTickedIcon : checkboxCrossedIcon;
+ newCell.innerHTML = record.writable == true ? checkboxTickedIcon : checkboxCrossedIcon;
newCell.align = 'center';
var newCell = newRow.insertCell(2);
- newCell.innerHTML = record.writable == true ? checkboxTickedIcon : checkboxCrossedIcon;
+ newCell.innerHTML = record.custom == true ? checkboxTickedIcon : checkboxIcon;
newCell.align = 'center';
+ if ( record.to_delete == true ) {
+ $(newRow).children().css('backgroundColor', '#ffc8c8');
+ } else if ( record.exists == true ) {
+ $(newRow).children().css('backgroundColor', '#ffebc8');
+ } else if ( record.exists == false ) {
+ $(newRow).children().css('backgroundColor', '#ceffc8');
+ }
+
rowCounter++;
}
}
View
8 osCommerce/OM/Core/Site/Admin/languages/en_US/CoreUpdate.php
@@ -12,8 +12,12 @@
table_heading_action = Action
table_heading_files = Files
-table_heading_file_replace = Replace
table_heading_file_writable = Writable
+table_heading_file_custom = Custom
+
+legend_new = NEW
+legend_modified = MODIFIED
+legend_to_delete = TO DELETE
action_heading_apply = Core Update: Update from v%s to v%s
@@ -22,6 +26,8 @@
icon_view_announcement = View Announcement
icon_view_contents = View Contents
+up_to_date = This installation is up to date!
+
ms_error_select_version_to_view = Error: Please select an available package version to view.
ms_error_local_update_package_does_not_exist = Error: Cannot download and save the update package. Please verify the osCommerce/OM/Work/CoreUpdate directory permissions and try again.
ms_error_wrong_version_to_update_from = Error: Please verify the package to update from.
Please sign in to comment.
Something went wrong with that request. Please try again.