Permalink
Browse files

Introduce CoreUpdate Admin Application to check, view, and apply core…

… updates
  • Loading branch information...
1 parent a689aa8 commit ad8d95a3d58f56ba1db7cfbb329e89260477ac72 @haraldpdl haraldpdl committed Mar 21, 2011
Showing with 881 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +40 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Action/Apply.php
  3. +43 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Action/Apply/Process.php
  4. +28 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Controller.php
  5. +14 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/CoreUpdate.php
  6. +37 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/applyPackage.php
  7. +28 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/canApplyPackage.php
  8. +21 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/deletePackage.php
  9. +38 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/downloadPackage.php
  10. +30 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/findAvailablePackages.php
  11. +30 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/findPackageContents.php
  12. +30 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/getAvailablePackageInfo.php
  13. +60 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/getAvailablePackages.php
  14. +85 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/getPackageContents.php
  15. +41 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/getPackageInfo.php
  16. +20 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/localPackageExists.php
  17. +28 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/Model/packageExists.php
  18. +33 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/RPC/GetAvailablePackages.php
  19. +33 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/RPC/GetPackageContents.php
  20. +100 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/pages/main.php
  21. +102 −0 osCommerce/OM/Core/Site/Admin/Application/CoreUpdate/pages/package_contents.php
  22. +33 −0 osCommerce/OM/Core/Site/Admin/languages/en_US/CoreUpdate.php
  23. +6 −0 osCommerce/OM/Work/CoreUpdate/update.phar.pubkey
  24. BIN public/sites/Admin/images/applications/16/coreupdate.png
  25. BIN public/sites/Admin/images/applications/32/coreupdate.png
  26. BIN public/sites/Admin/templates/oscom/images/icons/16x16/folder_contents.png
View
@@ -1,4 +1,5 @@
osCommerce/OM/Work/*
+!osCommerce/OM/Work/CoreUpdate/update.phar.pubkey
osCommerce/OM/Config/local_settings.ini
osCommerce/OM/Custom/*
!osCommerce/OM/Custom/README
@@ -0,0 +1,40 @@
+<?php
+/*
+ osCommerce Online Merchant $osCommerce-SIG$
+ Copyright (c) 2010 osCommerce (http://www.oscommerce.com)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License v2 (1991)
+ as published by the Free Software Foundation.
+*/
+
+ namespace osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\Action;
+
+ use osCommerce\OM\Core\ApplicationAbstract;
+ use osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\CoreUpdate;
+ use osCommerce\OM\Core\Registry;
+ use osCommerce\OM\Core\OSCOM;
+
+ class Apply {
+ public static function execute(ApplicationAbstract $application) {
+ if ( !isset($_GET['v']) || !CoreUpdate::packageExists($_GET['v']) ) {
+ Registry::get('MessageStack')->add(null, OSCOM::getDef('ms_error_select_version_to_view'), 'error');
+
+ osc_redirect_admin(OSCOM::getLink());
+ }
+
+ if ( CoreUpdate::localPackageExists() && (CoreUpdate::getPackageInfo('version_to') != $_GET['v']) ) {
+ CoreUpdate::deletePackage();
+ }
+
+ if ( !CoreUpdate::localPackageExists() && !CoreUpdate::downloadPackage($_GET['v']) ) {
+ Registry::get('MessageStack')->add(null, OSCOM::getDef('ms_error_local_update_package_does_not_exist'), 'error');
+
+ osc_redirect_admin(OSCOM::getLink());
+ }
+
+ $application->setPageContent('package_contents.php');
+ $application->setPageTitle(sprintf(OSCOM::getDef('action_heading_apply'), CoreUpdate::getPackageInfo('version_from'), CoreUpdate::getPackageInfo('version_to')));
+ }
+ }
+?>
@@ -0,0 +1,43 @@
+<?php
+/*
+ osCommerce Online Merchant $osCommerce-SIG$
+ Copyright (c) 2010 osCommerce (http://www.oscommerce.com)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License v2 (1991)
+ as published by the Free Software Foundation.
+*/
+
+ namespace osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\Action\Apply;
+
+ use osCommerce\OM\Core\ApplicationAbstract;
+ use osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\CoreUpdate;;
+ use osCommerce\OM\Core\Registry;
+ use osCommerce\OM\Core\OSCOM;
+
+ class Process {
+ public static function execute(ApplicationAbstract $application) {
+ if ( !CoreUpdate::localPackageExists() || (CoreUpdate::getPackageInfo('version_from') != OSCOM::getVersion()) ) {
+ Registry::get('MessageStack')->add(null, OSCOM::getDef('ms_error_wrong_version_to_update_from'), 'error');
+
+ osc_redirect_admin(OSCOM::getLink());
+ }
+
+ if ( CoreUpdate::canApplyPackage() ) {
+ if ( CoreUpdate::applyPackage() ) {
+ CoreUpdate::deletePackage();
+
+ Registry::get('MessageStack')->add(null, OSCOM::getDef('ms_success_action_performed'), 'success');
+ } else {
+ Registry::get('MessageStack')->add(null, OSCOM::getDef('ms_error_action_not_performed'), 'error');
+ }
+ } else {
+ Registry::get('MessageStack')->add(null, OSCOM::getDef('ms_error_check_target_permissions'), 'error');
+
+ osc_redirect_admin(OSCOM::getLink(null, null, 'Apply&v=' . $_GET['v']));
+ }
+
+ osc_redirect_admin(OSCOM::getLink());
+ }
+ }
+?>
@@ -0,0 +1,28 @@
+<?php
+/*
+ osCommerce Online Merchant $osCommerce-SIG$
+ Copyright (c) 2010 osCommerce (http://www.oscommerce.com)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License v2 (1991)
+ as published by the Free Software Foundation.
+*/
+
+ namespace osCommerce\OM\Core\Site\Admin\Application\CoreUpdate;
+
+ use osCommerce\OM\Core\OSCOM;
+
+ class Controller extends \osCommerce\OM\Core\Site\Admin\ApplicationAbstract {
+ protected $_group = 'tools';
+ protected $_icon = 'coreupdate.png';
+ protected $_sort_order = 5;
+
+ protected function initialize() {
+ $this->_title = OSCOM::getDef('app_title');
+ }
+
+ protected function process() {
+ $this->_page_title = OSCOM::getDef('heading_title');
+ }
+ }
+?>
@@ -0,0 +1,14 @@
+<?php
+/*
+ osCommerce Online Merchant $osCommerce-SIG$
+ Copyright (c) 2010 osCommerce (http://www.oscommerce.com)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License v2 (1991)
+ as published by the Free Software Foundation.
+*/
+
+ namespace osCommerce\OM\Core\Site\Admin\Application\CoreUpdate;
+
+ class CoreUpdate extends \osCommerce\OM\Core\ApplicationModelAbstract { }
+?>
@@ -0,0 +1,37 @@
+<?php
+/*
+ osCommerce Online Merchant $osCommerce-SIG$
+ Copyright (c) 2010 osCommerce (http://www.oscommerce.com)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License v2 (1991)
+ as published by the Free Software Foundation.
+*/
+
+ namespace osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\Model;
+
+ use \Phar;
+ use osCommerce\OM\Core\OSCOM;
+
+ class applyPackage {
+ public static function execute() {
+ $phar_can_open = true;
+
+ try {
+ $phar = new Phar(OSCOM::BASE_DIRECTORY . 'Work/CoreUpdate/update.phar');
+ $phar->extractTo(realpath(OSCOM::BASE_DIRECTORY . '../../'), null, true);
+ } 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;
+
+ trigger_error($e->getMessage());
+ }
+ }
+
+ return $phar_can_open;
+ }
+ }
+?>
@@ -0,0 +1,28 @@
+<?php
+/*
+ osCommerce Online Merchant $osCommerce-SIG$
+ Copyright (c) 2010 osCommerce (http://www.oscommerce.com)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License v2 (1991)
+ as published by the Free Software Foundation.
+*/
+
+ namespace osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\Model;
+
+ use osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\CoreUpdate;
+
+ class canApplyPackage {
+ public static function execute() {
+ $contents = CoreUpdate::getPackageContents();
+
+ foreach ( $contents['entries'] as $file ) {
+ if ( $file['writable'] === false ) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ }
+?>
@@ -0,0 +1,21 @@
+<?php
+/*
+ osCommerce Online Merchant $osCommerce-SIG$
+ Copyright (c) 2010 osCommerce (http://www.oscommerce.com)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License v2 (1991)
+ as published by the Free Software Foundation.
+*/
+
+ namespace osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\Model;
+
+ use \Phar;
+ use osCommerce\OM\Core\OSCOM;
+
+ class deletePackage {
+ public static function execute() {
+ return Phar::unlinkArchive(OSCOM::BASE_DIRECTORY . 'Work/CoreUpdate/update.phar');
+ }
+ }
+?>
@@ -0,0 +1,38 @@
+<?php
+/*
+ osCommerce Online Merchant $osCommerce-SIG$
+ Copyright (c) 2010 osCommerce (http://www.oscommerce.com)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License v2 (1991)
+ as published by the Free Software Foundation.
+*/
+
+ namespace osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\Model;
+
+ use osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\CoreUpdate;
+ use osCommerce\OM\Core\HttpRequest;
+ use osCommerce\OM\Core\OSCOM;
+
+ class downloadPackage {
+ public static function execute($version = null) {
+ if ( empty($version) ) {
+ $link = CoreUpdate::getAvailablePackageInfo('update_package');
+ } else {
+ $versions = CoreUpdate::getAvailablePackages();
+
+ foreach ( $versions['entries'] as $v ) {
+ if ( $v['version'] == $version ) {
+ $link = $v['update_package'];
+
+ break;
+ }
+ }
+ }
+
+ $response = HttpRequest::getResponse(array('url' => $link, 'parameters' => 'check=true'));
+
+ return file_put_contents(OSCOM::BASE_DIRECTORY . 'Work/CoreUpdate/update.phar', $response);
+ }
+ }
+?>
@@ -0,0 +1,30 @@
+<?php
+/*
+ osCommerce Online Merchant $osCommerce-SIG$
+ Copyright (c) 2010 osCommerce (http://www.oscommerce.com)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License v2 (1991)
+ as published by the Free Software Foundation.
+*/
+
+ namespace osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\Model;
+
+ use osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\CoreUpdate;
+
+ class findAvailablePackages {
+ public static function execute($search) {
+ $result = CoreUpdate::getAvailablePackages();
+
+ foreach ( $result['entries'] as $k => $v ) {
+ if ( strpos($v['version'], $search) === false ) {
+ unset($result['entries'][$k]);
+ }
+ }
+
+ $result['total'] = count($result['entries']);
+
+ return $result;
+ }
+ }
+?>
@@ -0,0 +1,30 @@
+<?php
+/*
+ osCommerce Online Merchant $osCommerce-SIG$
+ Copyright (c) 2010 osCommerce (http://www.oscommerce.com)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License v2 (1991)
+ as published by the Free Software Foundation.
+*/
+
+ namespace osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\Model;
+
+ use osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\CoreUpdate;
+
+ class findPackageContents {
+ public static function execute($search) {
+ $result = CoreUpdate::getPackageContents();
+
+ foreach ( $result['entries'] as $k => $v ) {
+ if ( strpos($v['name'], $search) === false ) {
+ unset($result['entries'][$k]);
+ }
+ }
+
+ $result['total'] = count($result['entries']);
+
+ return $result;
+ }
+ }
+?>
@@ -0,0 +1,30 @@
+<?php
+/*
+ osCommerce Online Merchant $osCommerce-SIG$
+ Copyright (c) 2010 osCommerce (http://www.oscommerce.com)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License v2 (1991)
+ as published by the Free Software Foundation.
+*/
+
+ namespace osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\Model;
+
+ use osCommerce\OM\Core\Site\Admin\Application\CoreUpdate\CoreUpdate;
+
+ class getAvailablePackageInfo {
+ public static function execute($key = null) {
+ $versions = CoreUpdate::getAvailablePackages();
+
+ if ( !empty($versions['entries']) ) {
+ if ( !empty($key) && isset($versions['entries'][0][$key]) ) {
+ return $versions['entries'][0][$key];
+ } else {
+ return $versions['entries'][0];
+ }
+ }
+
+ return false;
+ }
+ }
+?>
Oops, something went wrong. Retry.

0 comments on commit ad8d95a

Please sign in to comment.