diff --git a/composer_installer.php b/composer_installer.php
index 60a11b468d..af9cd02d35 100644
--- a/composer_installer.php
+++ b/composer_installer.php
@@ -81,7 +81,7 @@ function command($phpPath)
exec($command, $out, $code);
if ($code !== 0) throw new Exception('composer のアップデートに失敗しました。(' . $command . ')');
- $command = "cd " . ROOT_DIR . "; export HOME={$composerDir} ; yes | {$phpPath} {$composerDir}composer.phar update --ignore-platform-req=ext-xdebug";
+ $command = "cd " . ROOT_DIR . "; export HOME={$composerDir} ; yes | {$phpPath} {$composerDir}composer.phar install --ignore-platform-req=ext-xdebug";
exec($command, $out, $code);
if ($code !== 0) throw new Exception('ライブラリのインストールに失敗しました。
コマンド実行をお試しください
' . $command);
diff --git a/plugins/baser-core/config/setting.php b/plugins/baser-core/config/setting.php
index ff74aed8af..7487ccf4f1 100644
--- a/plugins/baser-core/config/setting.php
+++ b/plugins/baser-core/config/setting.php
@@ -291,12 +291,6 @@
*/
'coreReleaseUrl' => 'https://packagist.org/feeds/package.baserproject/baser-core.rss',
- /**
- * インストール時に composer.json にセットするバージョン
- * @see \BaserCore\Utility\BcComposer::setupComposerForDistribution()
- */
- 'setupVersion' => '5.1.*',
-
/**
* リリースパッケージに不要なファイル
* @see \BaserCore\Command\CreateReleaseCommand::deleteExcludeFiles()
diff --git a/plugins/baser-core/src/Command/CreateReleaseCommand.php b/plugins/baser-core/src/Command/CreateReleaseCommand.php
index 1e15705cfe..e1911afcb2 100644
--- a/plugins/baser-core/src/Command/CreateReleaseCommand.php
+++ b/plugins/baser-core/src/Command/CreateReleaseCommand.php
@@ -39,6 +39,10 @@ class CreateReleaseCommand extends Command
*/
protected function buildOptionParser(\Cake\Console\ConsoleOptionParser $parser): \Cake\Console\ConsoleOptionParser
{
+ $parser->addArgument('version', [
+ 'help' => __d('baser_core', 'リリースバージョン'),
+ 'required' => true
+ ]);
$parser->addArgument('branch', [
'help' => __d('baser_core', 'クローン対象ブランチ'),
'default' => 'master',
@@ -62,6 +66,7 @@ public function execute(Arguments $args, ConsoleIo $io)
if(is_dir($packagePath)) {
(new BcFolder($packagePath))->delete();
}
+ $version = $args->getArgument('version');
$io->out(__d('baser_core', 'リリースパッケージを作成します。', TMP));
$io->out();
@@ -69,8 +74,18 @@ public function execute(Arguments $args, ConsoleIo $io)
$io->out(__d('baser_core', '- {0} にパッケージをクローンします。', TMP));
$this->clonePackage($packagePath, $args->getArgument('branch'));
- $io->out(__d('baser_core', '- composer.json をセットアップします。'));
- BcComposer::setupComposerForDistribution($packagePath);
+ $io->out(__d('baser_core', '- composer.json / composer.lock をセットアップします。'));
+ BcComposer::setup('', $packagePath);
+ $result = BcComposer::setupComposerForDistribution($version, true);
+ if($result['code'] === 0) {
+ $io->out(__d('baser_core', 'Composer による lock ファイルの更新に失敗アップデートが完了しました。'));
+ } else {
+ $message = __d('baser_core', 'Composer による lock ファイルの更新に失敗しました。ログを確認してください。');
+ $this->log($message);
+ $this->log(implode("\n", $result['out']));
+ $io->error($message);
+ $this->abort();
+ }
$io->out(__d('baser_core', '- プラグインを初期化します。'));
$this->deletePlugins($packagePath);
@@ -79,7 +94,7 @@ public function execute(Arguments $args, ConsoleIo $io)
$this->deleteExcludeFiles($packagePath);
$io->out(__d('baser_core', '- Zip ファイルを作成します。'));
- $this->createZip($packagePath);
+ $this->createZip($packagePath, $version);
$io->out(__d('baser_core', '- クリーニング処理を実行します。'));
(new BcFolder($packagePath))->delete();
@@ -130,10 +145,10 @@ public function deletePlugins(string $packagePath)
* @noTodo
* @unitTest
*/
- public function createZip(string $packagePath)
+ public function createZip(string $packagePath, string $version)
{
$zip = new ZipArchiver();
- $zipFile = TMP . 'basercms.zip';
+ $zipFile = TMP . 'basercms-' . $version . '.zip';
if(file_exists($zipFile)) {
unlink($zipFile);
}
diff --git a/plugins/baser-core/src/Utility/BcComposer.php b/plugins/baser-core/src/Utility/BcComposer.php
index 7e470e0d59..be9b1710fd 100644
--- a/plugins/baser-core/src/Utility/BcComposer.php
+++ b/plugins/baser-core/src/Utility/BcComposer.php
@@ -69,6 +69,9 @@ class BcComposer
public static function setup(string $php = '', $dir = '')
{
self::checkEnv();
+ if(!preg_match('/\/$/', $dir)) {
+ $dir .= '/';
+ }
self::$currentDir = $dir;
self::$cd = ($dir)? "cd " . $dir . ';': "cd " . ROOT . DS . ';';
self::$composerDir = ROOT . DS . 'composer' . DS;
@@ -246,27 +249,22 @@ public static function createCommand(string $command)
/**
* 配布用に composer.json をセットアップする
- * @param string $packagePath
- * @return void
+ * @param string $version
+ * @return array
* @noTodo
* @checked
* @unitTest
*/
- public static function setupComposerForDistribution(string $packagePath)
+ public static function setupComposerForDistribution(string $version)
{
- $composer = $packagePath . 'composer.json';
- $file = new BcFile($composer);
- $data = $file->read();
- $regex = '/^(.+?) "replace": {.+?},\n(.+?)/s';
- $data = preg_replace($regex, "$1$2", $data);
- $regex = '/^(.+?"cakephp\/cakephp": ".+?",)(.+?)$/s';
- $setupVersion = Configure::read('BcApp.setupVersion');
- $replace = "$1\n \"baserproject/baser-core\": \"{$setupVersion}\",$2";
- $data = preg_replace($regex, $replace, $data);
- $file->write($data);
+ self::deleteReplace();
+ $result = self::require('baser-core', $version);
+ (new BcFolder(self::$currentDir . 'vendor'))->delete();
+ mkdir(self::$currentDir . 'vendor');
+ (new BcFile(self::$currentDir . 'vendor' . DS . '.gitkeep'))->create();
+ return $result;
}
-
/**
* changeMinimumStabilityToDev
*
@@ -276,7 +274,7 @@ public static function setupComposerForDistribution(string $packagePath)
*/
public static function changeMinimumStabilityToDev()
{
- $file = new BcFile(self::$currentDir . DS . 'composer.json');
+ $file = new BcFile(self::$currentDir . 'composer.json');
$json = $file->read();
if(strpos($json, '"minimum-stability"') !== false) {
@@ -299,7 +297,7 @@ public static function changeMinimumStabilityToDev()
*/
public static function deleteReplace()
{
- $file = new BcFile(self::$currentDir . DS . 'composer.json');
+ $file = new BcFile(self::$currentDir . 'composer.json');
$json = $file->read();
$json = preg_replace('/"replace"\s*:\s*?{[^}]+?},/', '', $json);
$file->write($json);
diff --git a/plugins/baser-core/tests/TestCase/Command/ComposerCommandTest.php b/plugins/baser-core/tests/TestCase/Command/ComposerCommandTest.php
index 4e4fad2e58..c1a471b2f7 100644
--- a/plugins/baser-core/tests/TestCase/Command/ComposerCommandTest.php
+++ b/plugins/baser-core/tests/TestCase/Command/ComposerCommandTest.php
@@ -73,7 +73,8 @@ public function testExecute()
$this->assertErrorContains('Composer によるアップデートが失敗しました。update ログを確認してください。');
// composer実行(composer.json を配布用にセットアップ)
- BcComposer::setupComposerForDistribution(ROOT . DS);
+ BcComposer::setup('', ROOT . DS);
+ BcComposer::setupComposerForDistribution('5.0.15');
$this->exec('composer 5.0.15');
$this->assertExitCode(Command::CODE_SUCCESS);
$this->assertOutputContains('Composer によるアップデートが完了しました。');
@@ -104,7 +105,8 @@ public function testExecuteOnUpdateTmp()
copy(ROOT . DS . 'composer.json', TMP . 'update' . DS . 'composer.json');
copy(ROOT . DS . 'composer.lock', TMP . 'update' . DS . 'composer.lock');
// composer.json を配布用にセットアップ
- BcComposer::setupComposerForDistribution(TMP . 'update' . DS);
+ BcComposer::setup('', TMP . 'update' . DS);
+ BcComposer::setupComposerForDistribution('5.0.15');
// composer 実行
$this->exec('composer 5.0.15 --dir ' . TMP . 'update');
// バージョンを確認
diff --git a/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php b/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php
index 382b8f7ba0..baa4b07bcf 100644
--- a/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php
+++ b/plugins/baser-core/tests/TestCase/Controller/Admin/PluginsControllerTest.php
@@ -369,7 +369,8 @@ public function test_get_core_update()
copy(ROOT . DS . 'composer.lock', ROOT . DS . 'composer.bak.lock');
// composer.json を配布用に更新
- BcComposer::setupComposerForDistribution(ROOT . DS);
+ BcComposer::setup('', ROOT . DS);
+ BcComposer::setupComposerForDistribution('5.0.15');
$this->post('/baser/admin/baser-core/plugins/get_core_update', [
'targetVersion' => '5.0.15',
diff --git a/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php b/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php
index c9fd67a7d6..1cc3f8a0ba 100644
--- a/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php
+++ b/plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php
@@ -573,7 +573,8 @@ public function testGetCoreUpdateAndUpdateCoreFiles()
copy(ROOT . DS . 'composer.lock', ROOT . DS . 'composer.bak.lock');
// composer.json を配布用に更新
- BcComposer::setupComposerForDistribution(ROOT . DS);
+ BcComposer::setup('', ROOT . DS);
+ BcComposer::setupComposerForDistribution('5.0.15');
// getCoreUpdate 実行
$this->Plugins->getCoreUpdate('5.0.15', 'php');
@@ -615,7 +616,8 @@ public function testRollbackCore()
// composer.json をバックアップ
copy(ROOT . DS . 'composer.json', ROOT . DS . 'composer.bak.json');
// composer.json を配布用に更新
- BcComposer::setupComposerForDistribution(ROOT . DS);
+ BcComposer::setup('', ROOT . DS);
+ BcComposer::setupComposerForDistribution('5.1.1');
// ロールバック
$this->Plugins->rollbackCore('5.0.15', 'php');
diff --git a/plugins/baser-core/tests/TestCase/Utility/BcComposerTest.php b/plugins/baser-core/tests/TestCase/Utility/BcComposerTest.php
index e3b5d6ce61..06cf352932 100644
--- a/plugins/baser-core/tests/TestCase/Utility/BcComposerTest.php
+++ b/plugins/baser-core/tests/TestCase/Utility/BcComposerTest.php
@@ -239,18 +239,32 @@ public function testInstall()
public function testSetupComposerForDistribution()
{
// composer.json をバックアップ
- $composer = ROOT . DS . 'composer.json';
- copy($composer, ROOT . DS . 'composer.json.bak');
+ $composer = TMP_TESTS . 'composer.json';
+ copy(ROOT . DS . 'composer.json', $composer);
// 実行
- BcComposer::setupComposerForDistribution(ROOT . DS);
+ BcComposer::setup('', TMP_TESTS);
+
+ // 5.1.0 のテストの場合、5.1.1 との依存関係の問題があるためライブラリを調整
+ // このままでは、今後のリリースのタイミングでまた依存関係が変わる可能性があるため
+ // 特定のバージョンの composer.json を別途用意しておいた方が良さそう
+ // >>>
+ BcComposer::require('josegonzalez/dotenv', '^3.2');
+ sleep(1);
+ BcComposer::require('mobiledetect/mobiledetectlib', '^4.8.03');
+ // <<<
+
+ BcComposer::setupComposerForDistribution('5.1.0');
$file = new BcFile($composer);
$data = $file->read();
$this->assertNotFalse(strpos($data, '"baserproject/baser-core": '));
$this->assertFalse(strpos($data, '"replace": {'));
+ $this->assertFileExists(TMP_TESTS . 'composer.lock');
// バックアップをリストア
- rename(ROOT . DS . 'composer.json.bak', ROOT . DS . 'composer.json');
+ unlink($composer);
+ unlink(TMP_TESTS . 'composer.lock');
+ (new BcFolder(TMP_TESTS . 'vendor'))->delete();
}
/**