diff --git a/application/Espo/Controllers/Admin.php b/application/Espo/Controllers/Admin.php index 323d0b72b2..70fd350e47 100644 --- a/application/Espo/Controllers/Admin.php +++ b/application/Espo/Controllers/Admin.php @@ -35,7 +35,7 @@ use Espo\Core\{ Utils\AdminNotificationManager, Utils\SystemRequirements, Utils\ScheduledJob, - UpgradeManager, + Upgrades\UpgradeManager, Exceptions\Forbidden, Api\Request, }; diff --git a/application/Espo/Controllers/Extension.php b/application/Espo/Controllers/Extension.php index 80ba5a69ee..4831293d65 100644 --- a/application/Espo/Controllers/Extension.php +++ b/application/Espo/Controllers/Extension.php @@ -32,7 +32,7 @@ namespace Espo\Controllers; use Espo\Core\Exceptions\Forbidden; use Espo\Core\{ - ExtensionManager, + Upgrades\ExtensionManager, Controllers\RecordBase, Api\Request, Api\Response, diff --git a/application/Espo/Core/Console/Commands/Extension.php b/application/Espo/Core/Console/Commands/Extension.php index c46c421c4a..4f45560352 100644 --- a/application/Espo/Core/Console/Commands/Extension.php +++ b/application/Espo/Core/Console/Commands/Extension.php @@ -30,7 +30,7 @@ namespace Espo\Core\Console\Commands; use Espo\Core\{ - ExtensionManager, + Upgrades\ExtensionManager, Container, Console\Command, Console\Params, @@ -227,7 +227,7 @@ class Extension implements Command } } - protected function createExtensionManager() + protected function createExtensionManager(): ExtensionManager { return new ExtensionManager($this->container); } diff --git a/application/Espo/Core/Console/Commands/Upgrade.php b/application/Espo/Core/Console/Commands/Upgrade.php index 19470877b3..254332c823 100644 --- a/application/Espo/Core/Console/Commands/Upgrade.php +++ b/application/Espo/Core/Console/Commands/Upgrade.php @@ -32,7 +32,7 @@ namespace Espo\Core\Console\Commands; use Espo\Core\{ Exceptions\Error, Application, - UpgradeManager, + Upgrades\UpgradeManager, Utils\Util, Utils\File\Manager as FileManager, Utils\Config, diff --git a/application/Espo/Core/Console/Commands/UpgradeStep.php b/application/Espo/Core/Console/Commands/UpgradeStep.php index 7dd87930c3..203af03252 100644 --- a/application/Espo/Core/Console/Commands/UpgradeStep.php +++ b/application/Espo/Core/Console/Commands/UpgradeStep.php @@ -32,7 +32,7 @@ namespace Espo\Core\Console\Commands; use Espo\Core\{ Container, Application, - UpgradeManager, + Upgrades\UpgradeManager, Console\Command, Console\Params, Console\IO, diff --git a/application/Espo/Core/Upgrades/Actions/Extension/Install.php b/application/Espo/Core/Upgrades/Actions/Extension/Install.php index 7e3022737c..7e60f3d905 100644 --- a/application/Espo/Core/Upgrades/Actions/Extension/Install.php +++ b/application/Espo/Core/Upgrades/Actions/Extension/Install.php @@ -29,7 +29,7 @@ namespace Espo\Core\Upgrades\Actions\Extension; -use Espo\Core\ExtensionManager; +use Espo\Core\Upgrades\ExtensionManager; use Espo\Core\Utils\Util; diff --git a/application/Espo/Core/ExtensionManager.php b/application/Espo/Core/Upgrades/ExtensionManager.php similarity index 90% rename from application/Espo/Core/ExtensionManager.php rename to application/Espo/Core/Upgrades/ExtensionManager.php index ce8272d444..6e63af703a 100644 --- a/application/Espo/Core/ExtensionManager.php +++ b/application/Espo/Core/Upgrades/ExtensionManager.php @@ -27,26 +27,25 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Core; +namespace Espo\Core\Upgrades; -class ExtensionManager extends Upgrades\Base +class ExtensionManager extends Base { protected $name = 'Extension'; - protected $params = array( + protected $params = [ 'packagePath' => 'data/upload/extensions', 'backupPath' => 'data/.backup/extensions', - 'scriptNames' => array( + 'scriptNames' => [ 'before' => 'BeforeInstall', 'after' => 'AfterInstall', 'beforeUninstall' => 'BeforeUninstall', 'afterUninstall' => 'AfterUninstall', - ), - - 'customDirNames' => array( + ], + 'customDirNames' => [ 'before' => 'beforeInstallFiles', 'after' => 'afterInstallFiles', - ) - ); + ], + ]; } diff --git a/application/Espo/Core/UpgradeManager.php b/application/Espo/Core/Upgrades/UpgradeManager.php similarity index 94% rename from application/Espo/Core/UpgradeManager.php rename to application/Espo/Core/Upgrades/UpgradeManager.php index c68617027b..8a3a51ab9b 100644 --- a/application/Espo/Core/UpgradeManager.php +++ b/application/Espo/Core/Upgrades/UpgradeManager.php @@ -27,11 +27,9 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -namespace Espo\Core; +namespace Espo\Core\Upgrades; -use Espo\Core\Exceptions\Error; - -class UpgradeManager extends Upgrades\Base +class UpgradeManager extends Base { protected $name = 'Upgrade'; diff --git a/extension.php b/extension.php index 3dd353eb9b..51b973747a 100644 --- a/extension.php +++ b/extension.php @@ -27,15 +27,20 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -if (substr(php_sapi_name(), 0, 3) != 'cli') exit; +if (substr(php_sapi_name(), 0, 3) !== 'cli') { + exit; +} include "bootstrap.php"; use Espo\Core\{ Application, ApplicationRunners\Rebuild, + Upgrades\ExtensionManager, }; +use Exception; + $arg = isset($_SERVER['argv'][1]) ? trim($_SERVER['argv'][1]) : ''; if (empty($arg)) { @@ -47,6 +52,7 @@ if (!file_exists($arg)) { } $pathInfo = pathinfo($arg); + if (!isset($pathInfo['extension']) || $pathInfo['extension'] !== 'zip' || !is_file($arg)) { die("Unsupported package.\n"); } @@ -57,7 +63,7 @@ $app->setupSystemUser(); $config = $app->getContainer()->get('config'); $entityManager = $app->getContainer()->get('entityManager'); -$upgradeManager = new \Espo\Core\ExtensionManager($app->getContainer()); +$upgradeManager = new ExtensionManager($app->getContainer()); echo "Starting installation process...\n"; @@ -67,12 +73,14 @@ try { $upgradeId = $upgradeManager->upload($fileData); $upgradeManager->install(array('id' => $upgradeId)); -} catch (\Exception $e) { +} +catch (Exception $e) { die("Error: " . $e->getMessage() . "\n"); } try { (new Application())->run(Rebuild::class); -} catch (\Exception $e) {} +} +catch (Exception $e) {} echo "Extension installation is complete.\n"; diff --git a/tests/integration/Espo/Extension/GeneralTest.php b/tests/integration/Espo/Extension/GeneralTest.php index 8743acb6e6..579eb1af14 100644 --- a/tests/integration/Espo/Extension/GeneralTest.php +++ b/tests/integration/Espo/Extension/GeneralTest.php @@ -29,11 +29,14 @@ namespace tests\integration\Espo\Extension; +use Espo\Core\Upgrades\ExtensionManager; + class GeneralTest extends \tests\integration\Core\BaseTestCase { protected $dataFile = 'InitData.php'; protected $userName = 'admin'; + protected $password = '1'; protected $packagePath = 'Extension/General.zip'; @@ -48,7 +51,7 @@ class GeneralTest extends \tests\integration\Core\BaseTestCase $fileData = file_get_contents($this->normalizePath($this->packagePath)); $fileData = 'data:application/zip;base64,' . base64_encode($fileData); - $extensionManager = new \Espo\Core\ExtensionManager($this->getContainer()); + $extensionManager = new ExtensionManager($this->getContainer()); $extensionId = $extensionManager->upload($fileData); $this->assertStringMatchesFormat('%x', $extensionId); @@ -62,7 +65,7 @@ class GeneralTest extends \tests\integration\Core\BaseTestCase { $extensionId = $this->testUpload(); - $extensionManager = new \Espo\Core\ExtensionManager($this->getContainer()); + $extensionManager = new ExtensionManager($this->getContainer()); $extensionManager->install(array('id' => $extensionId)); $this->assertFileExists('data/upload/extensions/' . $extensionId . 'z'); @@ -85,7 +88,7 @@ class GeneralTest extends \tests\integration\Core\BaseTestCase { $extensionId = $this->testInstall(); - $extensionManager = new \Espo\Core\ExtensionManager($this->getContainer()); + $extensionManager = new ExtensionManager($this->getContainer()); $extensionManager->uninstall(array('id' => $extensionId)); $this->assertFileDoesNotExist('data/.backup/extensions/' . $extensionId); //directory @@ -108,7 +111,7 @@ class GeneralTest extends \tests\integration\Core\BaseTestCase { $extensionId = $this->testUninstall(); - $extensionManager = new \Espo\Core\ExtensionManager($this->getContainer()); + $extensionManager = new ExtensionManager($this->getContainer()); $extensionManager->delete(array('id' => $extensionId)); $this->assertFileDoesNotExist('data/.backup/extensions/' . $extensionId); //directory diff --git a/tests/integration/Espo/Upgrade/GeneralTest.php b/tests/integration/Espo/Upgrade/GeneralTest.php index 89e7c91f82..cad96ad648 100644 --- a/tests/integration/Espo/Upgrade/GeneralTest.php +++ b/tests/integration/Espo/Upgrade/GeneralTest.php @@ -29,11 +29,14 @@ namespace tests\integration\Espo\Upgrade; +use Espo\Core\Upgrades\UpgradeManager; + class GeneralTest extends \tests\integration\Core\BaseTestCase { protected $dataFile = 'InitData.php'; protected $userName = 'admin'; + protected $password = '1'; protected $packagePath = 'Upgrade/General.zip'; @@ -43,7 +46,7 @@ class GeneralTest extends \tests\integration\Core\BaseTestCase $fileData = file_get_contents($this->normalizePath($this->packagePath)); $fileData = 'data:application/zip;base64,' . base64_encode($fileData); - $upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer()); + $upgradeManager = new UpgradeManager($this->getContainer()); $upgradeId = $upgradeManager->upload($fileData); $this->assertStringMatchesFormat('%x', $upgradeId); @@ -58,7 +61,8 @@ class GeneralTest extends \tests\integration\Core\BaseTestCase { $upgradeId = $this->testUpload(); - $upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer()); + $upgradeManager = new UpgradeManager($this->getContainer()); + $upgradeManager->install(array('id' => $upgradeId)); $this->assertFileDoesNotExist('data/upload/upgrades/' . $upgradeId . 'z'); @@ -79,7 +83,7 @@ class GeneralTest extends \tests\integration\Core\BaseTestCase $upgradeId = $this->testInstall(); - $upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer()); + $upgradeManager = new UpgradeManager($this->getContainer()); $upgradeManager->uninstall(array('id' => $upgradeId)); } @@ -89,7 +93,7 @@ class GeneralTest extends \tests\integration\Core\BaseTestCase $upgradeId = $this->testInstall(); - $upgradeManager = new \Espo\Core\UpgradeManager($this->getContainer()); + $upgradeManager = new UpgradeManager($this->getContainer()); $upgradeManager->delete(array('id' => $upgradeId)); } } diff --git a/tests/unit/Espo/Core/Upgrades/ActionManagerTest.php b/tests/unit/Espo/Core/Upgrades/ActionManagerTest.php index 271aaaba40..4f5de051c6 100644 --- a/tests/unit/Espo/Core/Upgrades/ActionManagerTest.php +++ b/tests/unit/Espo/Core/Upgrades/ActionManagerTest.php @@ -30,8 +30,8 @@ namespace tests\unit\Espo\Core\Upgrades; use tests\unit\ReflectionHelper, - Espo\Core\ExtensionManager, - Espo\Core\UpgradeManager; + Espo\Core\Upgrades\ExtensionManager, + Espo\Core\Upgrades\UpgradeManager; use Espo\Core\Utils\File\Manager as FileManager; diff --git a/upgrade.php b/upgrade.php index c0fc40191c..6e95a7ced3 100644 --- a/upgrade.php +++ b/upgrade.php @@ -27,19 +27,25 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -if (substr(php_sapi_name(), 0, 3) != 'cli') exit; +if (substr(php_sapi_name(), 0, 3) !== 'cli') { + exit; +} include "bootstrap.php"; use Espo\Core\{ Application, ApplicationRunners\Rebuild, + Upgrades\UpgradeManager, }; +use Exception; + $arg = isset($_SERVER['argv'][1]) ? trim($_SERVER['argv'][1]) : ''; if ($arg == 'version' || $arg == '-v') { - $app = new \Espo\Core\Application(); + $app = new Application(); + die("Current version is " . $app->getContainer()->get('config')->get('version') . ".\n"); } @@ -52,17 +58,19 @@ if (!file_exists($arg)) { } $pathInfo = pathinfo($arg); + if (!isset($pathInfo['extension']) || $pathInfo['extension'] !== 'zip' || !is_file($arg)) { die("Unsupported package.\n"); } $app = new Application(); + $app->setupSystemUser(); $config = $app->getContainer()->get('config'); $entityManager = $app->getContainer()->get('entityManager'); -$upgradeManager = new \Espo\Core\UpgradeManager($app->getContainer()); +$upgradeManager = new UpgradeManager($app->getContainer()); echo "Current version is " . $config->get('version') . "\n"; echo "Starting upgrade process...\n"; @@ -72,13 +80,16 @@ try { $fileData = 'data:application/zip;base64,' . base64_encode($fileData); $upgradeId = $upgradeManager->upload($fileData); + $upgradeManager->install(['id' => $upgradeId]); -} catch (\Exception $e) { +} +catch (Exception $e) { die("Error: " . $e->getMessage() . "\n"); } try { (new Application())->run(Rebuild::class); -} catch (\Exception $e) {} +} +catch (Exception $e) {} echo "Upgrade is complete. Current version is " . $config->get('version') . ". \n";