Author: XE Team (developers) (developers@xpressengine.com)
 /**
  * Execute the console command.
  *
  * @param ComposerFileWriter $writer
  *
  * @return bool|null
  * @throws \Exception
  */
 public function fire(ComposerFileWriter $writer)
 {
     // php artisan plugin:sync-composer
     // sync
     $writer->resolvePlugins()->setFixMode()->write();
     $this->output->success("The installation information of the plug-in was synchronized with the composer file(" . $writer->getPath() . ").");
 }
 /**
  * getChanged
  *
  * @param ComposerFileWriter $writer
  *
  * @return array
  */
 protected function getChangedPlugins(ComposerFileWriter $writer)
 {
     $changed = [];
     $changed['installed'] = $writer->get('xpressengine-plugin.operation.changed.installed', []);
     $changed['updated'] = $writer->get('xpressengine-plugin.operation.changed.updated', []);
     $changed['uninstalled'] = $writer->get('xpressengine-plugin.operation.changed.uninstalled', []);
     return $changed;
 }
 /**
  * Execute the console command.
  *
  * @param ComposerFileWriter  $writer
  * @param InterceptionHandler $interceptionHandler
  *
  * @return bool|null
  */
 public function fire(ComposerFileWriter $writer, InterceptionHandler $interceptionHandler)
 {
     // php artisan xe:update [version] [--skip-download]
     // title
     // Xpressengine을 업데이트합니다.
     $this->output->block('Updating Xpressengine.');
     // check option
     if (!$this->option('skip-download')) {
         // 업데이트 파일의 다운로드는 아직 지원하지 않습니다. 아래의 안내대로 코어를 업데이트 하십시오.
         $this->output->caution('Downloading update files does not yet supported. Follow the guide below for update.');
         $this->printGuide();
         return null;
     }
     // version 안내
     $installedVersion = trim(file_get_contents(storage_path('app/installed')));
     //  업데이트 버전 정보:
     $this->warn(' Version information:');
     $this->output->text("  {$installedVersion} -> " . __XE_VERSION__);
     // confirm
     if ($this->confirm("The Xpressengine ver." . __XE_VERSION__ . " will be updated. It may take up to a few minutes. \r\nDo you want to update?") === false) {
         //return;
     }
     // 플러그인 업데이트 잠금
     $writer->reset()->write();
     // composer update실행(composer update --no-dev)
     if (!$this->option('skip-composer')) {
         $this->output->section('Composer update command is running.. It may take up to a few minutes.');
         $this->line(" composer update");
         try {
             $this->runComposer(base_path(), "update");
         } catch (\Exception $e) {
         }
     }
     // migration
     $this->output->section('Running migration..');
     $this->migrateCore($installedVersion, __XE_VERSION__);
     // clear proxy
     $interceptionHandler->clearProxies();
     // mark installed
     $this->markInstalled();
     $this->output->success("Update the Xpressengine to ver." . __XE_VERSION__ . ".");
 }
Exemple #4
0
 /**
  * Execute the console command.
  *
  * @param ComposerFileWriter $writer
  *
  * @return bool|null
  */
 public function fire(ComposerFileWriter $writer)
 {
     // php artisan xe:update [version] [--skip-download]
     // title
     $this->output->block('Update Xpressengine.');
     // check option
     if (!$this->option('skip-download')) {
         $this->output->caution('Download the update file does not yet support. Update the core following the instructions below.');
         $this->printGuide();
         return;
     }
     // version 안내
     $installedVersion = trim(file_get_contents(storage_path('app/installed')));
     $this->warn(' Update version information:');
     $this->output->text("  {$installedVersion} -> " . __XE_VERSION__);
     // confirm
     if ($this->confirm("Update the Xpressengine ver." . __XE_VERSION__ . ". There is a maximum moisture is applied. \r\nDo you want to update?") === false) {
         //return;
     }
     // 플러그인 업데이트 잠금
     $writer->resolvePlugins()->setFixMode()->write();
     // composer update실행(composer update --no-dev)
     if (!$this->option('skip-composer')) {
         $this->output->section('Run the composer update. There is a maximum moisture is applied.');
         $this->line(" composer update");
         try {
             $this->runComposer(base_path(), "update");
         } catch (\Exception $e) {
         }
     }
     // migration
     $this->output->section('Run the migration of the Xpressengine.');
     $this->migrateCore($installedVersion, __XE_VERSION__);
     // mark installed
     $this->markInstalled();
     $this->output->success("Update the Xpressengine to ver." . __XE_VERSION__ . ".");
 }
 /**
  * plugin composer 파일에 등록된 플러그인 제어정보를 require에 적용한다.
  *
  * @param ComposerFileWriter $writer composer file writer
  *
  * @return void
  */
 private static function applyRequire(ComposerFileWriter $writer)
 {
     $installs = $writer->get('xpressengine-plugin.operation.install', []);
     foreach ($installs as $name => $version) {
         $writer->addRequire($name, $version);
     }
     $updates = $writer->get('xpressengine-plugin.operation.update', []);
     foreach ($updates as $name => $version) {
         $writer->addRequire($name, $version);
     }
     $uninstalls = $writer->get('xpressengine-plugin.operation.uninstall', []);
     foreach ($uninstalls as $name) {
         $writer->removeRequire($name);
     }
 }
 /**
  * 현재 진행중인 플러그인 설치 작업 내역을 반환한다.
  *
  * @param ComposerFileWriter $writer composer file writer
  *
  * @return array|null
  */
 public function getOperation(ComposerFileWriter $writer)
 {
     $status = $writer->get('xpressengine-plugin.operation.status');
     if ($status === null) {
         return null;
     }
     $runnings = [];
     $runningMode = 'install';
     $runnings = $writer->get("xpressengine-plugin.operation.install", []);
     if (empty($runnings)) {
         $runningMode = 'update';
         $runnings = $writer->get("xpressengine-plugin.operation.update", []);
     }
     if (empty($runnings)) {
         $runningMode = 'uninstall';
         $runnings = $writer->get("xpressengine-plugin.operation.uninstall", []);
     }
     // operation이 없을 경우, return void
     if (empty($runnings)) {
         return null;
     }
     // operation이 있다.
     // expired 조사
     $deadline = $writer->get('xpressengine-plugin.operation.expiration_time');
     $expired = false;
     if ($deadline !== null && $deadline !== 0) {
         $deadline = Carbon::parse($deadline);
         if ($deadline->isPast()) {
             $expired = true;
         }
     }
     $runningsInfo = [];
     if (!empty($runnings)) {
         if ($runningMode === 'uninstall') {
             $package = current($runnings);
         } else {
             $package = key($runnings);
         }
         list(, $id) = explode('/', $package);
         $runningsInfo[$package] = $this->provider->find($id);
         $runningsInfo[$package]->pluginId = $id;
     }
     $changed = $writer->get('xpressengine-plugin.operation.changed', []);
     foreach ($changed as $type) {
         foreach ($type as $package => $version) {
             list(, $id) = explode('/', $package);
             if (!isset($runningsInfo[$package])) {
                 $runningsInfo[$package] = $this->provider->find($id);
             }
         }
     }
     if ($status === ComposerFileWriter::STATUS_RUNNING && $expired === true) {
         $status = 'expired';
     }
     return compact('runnings', 'status', 'runningMode', 'expired', 'changed', 'runningsInfo');
 }
 /**
  * reserveInstall
  *
  * @param ComposerFileWriter $writer
  * @param int                $timeLimit
  */
 protected function reserveOperation(ComposerFileWriter $writer, $timeLimit, $callback = null)
 {
     set_time_limit($timeLimit);
     ignore_user_abort(true);
     ini_set('allow_url_fopen', '1');
     $memoryInBytes = function ($value) {
         $unit = strtolower(substr($value, -1, 1));
         $value = (int) $value;
         switch ($unit) {
             case 'g':
                 $value *= 1024;
                 // no break (cumulative multiplier)
             // no break (cumulative multiplier)
             case 'm':
                 $value *= 1024;
                 // no break (cumulative multiplier)
             // no break (cumulative multiplier)
             case 'k':
                 $value *= 1024;
         }
         return $value;
     };
     $memoryLimit = trim(ini_get('memory_limit'));
     // Increase memory_limit if it is lower than 1GB
     if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 1024 * 1024 * 1024) {
         ini_set('memory_limit', '1G');
     }
     /** @var \Illuminate\Foundation\Application $app */
     app()->terminating(function () use($writer, $callback) {
         $pid = getmypid();
         Log::info("[plugin operation] start running composer run [pid={$pid}]");
         // call `composer install` command programmatically
         $vendorName = PluginHandler::PLUGIN_VENDOR_NAME;
         $input = new ArrayInput(['command' => 'update', "--prefer-lowest", "--with-dependencies", '--working-dir' => base_path(), 'packages' => ["{$vendorName}/*"]]);
         $output = new BufferedOutput();
         $application = new Application();
         $application->setAutoExit(false);
         // prevent `$application->run` method from exitting the script
         if (!defined('__XE_PLUGIN_MODE__')) {
             define('__XE_PLUGIN_MODE__', true);
         }
         $code = $application->run($input, $output);
         $outputText = $output->fetch();
         file_put_contents(storage_path('logs/plugin.log'), $outputText);
         if (is_callable($callback)) {
             $callback($code);
         }
         $writer->load();
         if ($code !== 0) {
             $writer->set('xpressengine-plugin.operation.status', ComposerFileWriter::STATUS_FAILED);
         } else {
             $writer->set('xpressengine-plugin.operation.status', ComposerFileWriter::STATUS_SUCCESSED);
         }
         $writer->write();
         Log::info("[plugin operation] plugin operation finished. [exit code: {$code}, memory usage: " . memory_get_usage() . "]");
     });
 }