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;
}
}