public function fire(PluginHandler $handler, PluginProvider $provider, ComposerFileWriter $writer)
{
$this->init($handler, $provider, $writer);
// php artisan plugin:update <plugin name> [<version>]
$id = $this->argument('plugin_id');
$version = $this->argument('version');
// 플러그인이 이미 설치돼 있는지 검사
$plugin = $handler->getPlugin($id);
if ($plugin === null) {
// 설치되어 있지 않은 플러그인입니다.
throw new \Exception('Plugin not found');
}
if (file_exists($plugin->getPath('vendor'))) {
// 개발모드의 플러그인입니다. 개발모드의 플러그인은 업데이트 할 수 없습니다.
throw new \Exception('The plugin is in develop mode. Can\'t update plugin in develop mode.');
}
// 설치가능 환경인지 검사
// - check writable of composer.plugin.json
if (!is_writable($composerFile = storage_path('app/composer.plugins.json'))) {
// [$composerFile] 파일에 쓰기 권한이 없습니다. 플러그인을 설치하기 위해서는 이 파일의 쓰기 권한이 있어야 합니다.
throw new \Exception("You have been denied permission to acccess [{$composerFile}] file. To update the plugin, you must have write permission to access this this file.");
}
// - check writable of plugins/ directory
if (!is_writable($pluginDir = base_path('plugins'))) {
// [$pluginDir] 디렉토리에 쓰기 권한이 없습니다. 플러그인을 설치하기 위해서는 이 디렉토리의 쓰기 권한이 있어야 합니다.
throw new \Exception("You have been denied permission to acccess [{$pluginDir}] directory. To update the plugin, you must have write permissions to access this directory.");
}
// 자료실에서 플러그인 정보 조회
$pluginData = $provider->find($id);
if ($pluginData === null) {
// 설치할 플러그인[$id]을 자료실에서 찾지 못했습니다.
throw new \Exception("Can not find the plugin(" . $id . ") that should be updated from the Market-place.");
}
$title = $pluginData->title;
$name = $pluginData->name;
if ($version) {
$releaseData = $provider->findRelease($id, $version);
if ($releaseData === null) {
// 플러그인[$id]의 버전[$version]을 자료실에서 찾지 못했습니다.
throw new \Exception("Can not find version(" . $version . ") of the plugin(" . $id . ") that should be updated from the Market-place.");
}
}
$version = $version ?: $pluginData->latest_release->version;
// 플러그인 정보 출력
// 업데이트 플러그인 정보
$this->warn(PHP_EOL . " Information of the plugin that should be updated:");
$this->line(" {$title} - {$name}: {$plugin->getVersion()} -> {$version}" . PHP_EOL);
// 안내 멘트 출력
if ($this->input->isInteractive() && $this->confirm("The new version of above plugin will be downloaded and installed. \r\n Dependent plugins can be installed together. \r\n It may take up to a few minutes. Do you want to update the plugin?") === false) {
return;
}
// - plugins require info 갱신
$writer->reset()->cleanOperation();
// composer.plugins.json 업데이트
// - require에 설치할 플러그인 추가
$writer->update($name, $version, 0)->write();
$vendorName = PluginHandler::PLUGIN_VENDOR_NAME;
// composer update실행(composer update --prefer-lowest --with-dependencies xpressengine-plugin/plugin_id)
// composer update를 실행합니다. 최대 수분이 소요될 수 있습니다.
$this->warn('Composer update command is running.. It may take up to a few minutes.');
$this->line(" composer update --prefer-lowest --with-dependencies {$vendorName}/*");
try {
$result = $this->runComposer(base_path(), "update --prefer-lowest --with-dependencies {$vendorName}/*");
} catch (\Exception $e) {
}
// composer 실행을 마쳤습니다
$this->warn('Composer update command is finished.' . PHP_EOL);
// composer.plugins.json 파일을 다시 읽어들인다.
$writer->load();
if (!isset($result) || $result !== 0) {
$writer->set('xpressengine-plugin.operation.status', ComposerFileWriter::STATUS_FAILED);
} else {
$writer->set('xpressengine-plugin.operation.status', ComposerFileWriter::STATUS_SUCCESSED);
}
$writer->write();
// changed plugin list 정보 출력
$changed = $this->getChangedPlugins($writer);
$this->printChangedPlugins($changed);
if (array_get($changed, 'updated.' . $name) === $version) {
// 설치 성공 문구 출력
// $title - $name:$version 플러그인을 업데이트했습니다.
$this->output->success("{$title} - {$name}:{$version} plugin is updated");
} elseif (array_get($changed, 'updated.' . $name)) {
$this->output->warning("You update the plug-in of the \"" . $name . "\", but has now been updated on other versions(" . $version . "). Because of the dependencies between plug-ins, there is a possibility that has been updated in the other version. Please check the plug-in dependencies.");
} elseif ($plugin->getVersion() === $version) {
$this->output->warning("Because the plug-ins of the same version is installed, the update was not.");
} else {
$this->output->warning("Do not update the plug-in of the {$name}:{$version}. Update for the dependencies between plug-ins may become impossible. Please check the plug-in dependencies.");
}
}