Pagekit\Installer\SelfUpdater::update PHP Метод

update() публичный Метод

Runs Pagekit self update.
public update ( $file )
$file
    public function update($file)
    {
        try {
            $path = App::path();
            if (!file_exists($file)) {
                throw new \RuntimeException('File not found.');
            }
            $this->output->write('Preparing update...');
            $fileList = $this->getFileList($file);
            unset($fileList[array_search('.htaccess', $fileList)]);
            $fileList = array_values(array_filter($fileList, function ($file) {
                foreach ($this->ignoreFolder as $ignore) {
                    if (strpos($file, $ignore) === 0) {
                        return false;
                    }
                }
                return true;
            }));
            if ($this->isWritable($fileList, $path) !== true) {
                throw new \RuntimeException(array_reduce($fileList, function ($carry, $file) {
                    return $carry . sprintf("'%s' not writable\n", $file);
                }));
            }
            $requirements = (include "zip://{$file}#app/installer/requirements.php");
            if ($failed = $requirements->getFailedRequirements()) {
                throw new \RuntimeException(array_reduce($failed, function ($carry, $problem) {
                    return $carry . "\n" . $problem->getHelpText();
                }));
            }
            $this->output->writeln('<info>done.</info>');
            $this->output->write('Entering update mode...');
            $this->setUpdateMode(true);
            $this->output->writeln('<info>done.</info>');
            $this->output->write('Extracting files...');
            $this->extract($file, $fileList, $path);
            $this->output->writeln('<info>done.</info>');
            $this->output->write('Removing old files...');
            foreach ($this->cleanup($fileList, $path) as $file) {
                $this->writeln(sprintf('<error>\'%s\\’ could not be removed</error>', $file));
            }
            unlink($file);
            $this->output->writeln('<info>done.</info>');
            $this->output->write('Deactivating update mode...');
            $this->setUpdateMode(false);
            $this->output->writeln('<info>done.</info>');
            if (function_exists('opcache_reset')) {
                opcache_reset();
            }
        } catch (\Exception $e) {
            @unlink($file);
            throw $e;
        }
    }

Usage Example

Пример #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         if (!$this->option('url')) {
             $output->write('Requesting Version...');
             $versions = $this->getVersions();
             $output->writeln('<info>done.</info>');
             $output->writeln('');
             $output->writeln('<comment>Latest Version: ' . $versions['latest']['version'] . '</comment> ');
             $output->writeln('');
             if (!$this->confirm('Update to Version ' . $versions['latest']['version'] . '? [y/n]')) {
                 return;
             }
             $output->writeln('');
             $url = $versions['latest']['url'];
         } else {
             $url = $this->option('url');
         }
         $tmpFile = tempnam($this->container['path.temp'], 'update_');
         $output->write('Downloading...');
         $this->download($url, $tmpFile);
         $output->writeln('<info>done.</info>');
         $updater = new SelfUpdater($output);
         $updater->update($tmpFile);
         $output->write('Migrating...');
         system(sprintf('php %s migrate', $_SERVER['PHP_SELF']));
     } catch (\Exception $e) {
         if (isset($tmpFile) && file_exists($tmpFile)) {
             unlink($tmpFile);
         }
         throw $e;
     }
 }
All Usage Examples Of Pagekit\Installer\SelfUpdater::update