/** * @param \Pimple $pimple */ public function setup(\Pimple $pimple) { $me = $this; $pimple['db'] = function () use($me) { $conn = Utils::getConnection(SW_PATH); return $conn; }; $pimple['filesystem.factory'] = function () use($me) { $updateConfig = $me->getParameter('update.config'); $ftp = isset($updateConfig['ftp_credentials']) ? $updateConfig['ftp_credentials'] : array(); return new FilesystemFactory(SW_PATH, $ftp); }; $pimple['path.builder'] = function () use($me) { $baseDir = SW_PATH; $updateDir = UPDATE_FILES_PATH; $backupDir = SW_PATH . '/files/backup'; return new PathBuilder($baseDir, $updateDir, $backupDir); }; $pimple['migration.manager'] = function () use($me) { $migrationPath = UPDATE_ASSET_PATH . '/migrations/'; $db = $me->get('db'); $migrationManger = new MigrationManager($db, $migrationPath); return $migrationManger; }; $pimple['dump'] = function () use($me) { $snippetsSql = UPDATE_ASSET_PATH . '/snippets.sql'; $snippetsSql = file_exists($snippetsSql) ? $snippetsSql : null; if (!$snippetsSql) { return null; } return new Dump($snippetsSql); }; $pimple['app'] = function () use($me) { $slimOptions = $me->getParameter('slim'); $slim = new \Slim\Slim($slimOptions); $me->set('slim.request', $slim->request()); $me->set('slim.response', $slim->response()); return $slim; }; $pimple['controller.batch'] = function () use($me) { return new BatchController($me->get('slim.request'), $me->get('slim.response'), $me); }; }
public function checkRequirements() { $paths = Utils::getPaths(SW_PATH . "/engine/Shopware/Components/Check/Data/Path.xml"); clearstatcache(); $systemCheckPathResults = Utils::checkPaths($paths, SW_PATH); foreach ($systemCheckPathResults as $value) { if (!$value['result']) { $fileName = SW_PATH . '/' . $value['name']; @mkdir($fileName, 0777, true); @chmod($fileName, 0777); } } clearstatcache(); $systemCheckPathResults = Utils::checkPaths($paths, SW_PATH); $hasErrors = false; foreach ($systemCheckPathResults as $value) { if (!$value['result']) { $hasErrors = true; } } $directoriesToDelete = ['engine/Library/Mpdf/tmp' => false, 'engine/Library/Mpdf/ttfontdata' => false]; CommonUtils::clearOpcodeCache(); $results = []; foreach ($directoriesToDelete as $directory => $deleteDirecory) { $result = true; $filePath = SW_PATH . '/' . $directory; Utils::deleteDir($filePath, $deleteDirecory); if ($deleteDirecory && is_dir($filePath)) { $result = false; $hasErrors = true; } if ($deleteDirecory) { $results[$directory] = $result; } } if (!$hasErrors && $this->app->request()->get("force") !== "1") { // No errors, skip page except if force parameter is set $this->app->redirect($this->app->urlFor("dbmigration")); } $isSkippableCheck = $this->app->config('skippable.check'); if ($isSkippableCheck && $this->app->request()->get("force") !== "1") { // No errors, skip page except if force parameter is set $this->app->redirect($this->app->urlFor("dbmigration")); } $this->app->render('checks.php', ['systemCheckResultsWritePermissions' => $systemCheckPathResults, 'filesToDelete' => $results, 'error' => $hasErrors]); }
public function cleanupOldFiles() { $_SESSION['DB_DONE'] = true; $cleanupList = array_merge($this->pluginFinder->getDummyPlugins(), $this->filesFinder->getCleanupFiles()); $this->cleanupMedia(); if (count($cleanupList) == 0) { $_SESSION['CLEANUP_DONE'] = true; $this->response->redirect($this->app->urlFor('done')); } if ($this->request->isPost()) { $result = []; foreach ($cleanupList as $path) { $result = array_merge($result, Utils::cleanPath($path)); } if (count($result) == 0) { $_SESSION['CLEANUP_DONE'] = true; $this->response->redirect($this->app->urlFor('done')); } else { $result = array_map(function ($path) { return substr($path, strlen(SW_PATH) + 1); }, $result); $this->app->render('cleanup.php', ['cleanupList' => $result, 'error' => true]); } } else { $cleanupList = array_map(function ($path) { return substr($path, strlen(SW_PATH) + 1); }, $cleanupList); $this->app->render('cleanup.php', ['cleanupList' => $cleanupList, 'error' => false]); } }
private function cleanupCache() { $cachePath = SW_PATH . '/var/cache'; foreach (new \DirectoryIterator($cachePath) as $cacheDirectory) { if ($cacheDirectory->isDot() || !$cacheDirectory->isDir()) { continue; } Utils::deleteDir($cacheDirectory->getPathname(), true); } }
$cleanupList = array(); foreach ($rawList as $path) { $realpath = SW_PATH . '/' . $path; if (file_exists($realpath)) { $cleanupList[] = $path; } } if (count($cleanupList) == 0) { $_SESSION['CLEANUP_DONE'] = true; $url = $app->urlFor('done'); $app->response()->redirect($url); } if ($app->request()->isPost()) { $result = array(); foreach ($cleanupList as $path) { $result = array_merge($result, Utils::cleanPath(SW_PATH . '/' . $path)); } if (count($result) == 0) { $_SESSION['CLEANUP_DONE'] = true; $url = $app->urlFor('done'); $app->response()->redirect($url); } else { $result = array_map(function ($path) { return substr($path, strlen(realpath(__DIR__ . '/../../../')) + 1); }, $result); $app->render('cleanup.php', array('cleanupList' => $result, 'error' => true)); } } else { $app->render('cleanup.php', array('cleanupList' => $cleanupList, 'error' => false)); } })->via('GET', 'POST')->name('cleanup');
private function cleanup() { $this->output->writeln("Cleanup old files, clearing caches..."); $cleanupFile = UPDATE_ASSET_PATH . '/cleanup.php'; if (!is_file($cleanupFile)) { return; } $rawList = (require $cleanupFile); $cleanupList = array(); foreach ($rawList as $path) { $realpath = SW_PATH . '/' . $path; if (file_exists($realpath)) { $cleanupList[] = $path; } } foreach ($cleanupList as $path) { Utils::cleanPath(SW_PATH . '/' . $path); } $directoriesToDelete = array('cache/proxies/' => false, 'cache/doctrine/filecache/' => false, 'cache/doctrine/proxies/' => false, 'cache/doctrine/attributes/' => false, 'cache/general/' => false, 'cache/templates/' => false, 'engine/Library/Mpdf/tmp' => false, 'engine/Library/Mpdf/ttfontdata' => false); foreach ($directoriesToDelete as $directory => $deleteDirecory) { $filePath = SW_PATH . '/' . $directory; Utils::deleteDir($filePath, $deleteDirecory); } }
/** * @param \Pimple\Container $container */ public function setup(\Pimple\Container $container) { $me = $this; $container['shopware.version'] = function () use($me) { $version = trim(file_get_contents(UPDATE_ASSET_PATH . '/version')); return $version; }; $container['db'] = function () use($me) { $conn = Utils::getConnection(SW_PATH); return $conn; }; $container['filesystem.factory'] = function () use($me) { $updateConfig = $me->getParameter('update.config'); $ftp = isset($updateConfig['ftp_credentials']) ? $updateConfig['ftp_credentials'] : []; return new FilesystemFactory(SW_PATH, $ftp); }; $container['path.builder'] = function () use($me) { $baseDir = SW_PATH; $updateDir = UPDATE_FILES_PATH; $backupDir = SW_PATH . '/files/backup'; return new PathBuilder($baseDir, $updateDir, $backupDir); }; $container['migration.manager'] = function () use($me) { $migrationPath = UPDATE_ASSET_PATH . '/migrations/'; $db = $me->get('db'); $migrationManger = new MigrationManager($db, $migrationPath); return $migrationManger; }; $container['dump'] = function () use($me) { $snippetsSql = UPDATE_ASSET_PATH . '/snippets.sql'; $snippetsSql = file_exists($snippetsSql) ? $snippetsSql : null; if (!$snippetsSql) { return null; } return new DumpIterator($snippetsSql); }; $container['app'] = function () use($me) { $slimOptions = $me->getParameter('slim'); $slim = new \Slim\Slim($slimOptions); $me->set('slim.request', $slim->request()); $me->set('slim.response', $slim->response()); return $slim; }; $container['http-client'] = function () { return new CurlClient(); }; $container['store.api'] = function () use($me) { return new StoreApi($me->get('http-client'), $me->getParameter('storeapi.endpoint')); }; $container['plugin.check'] = function () use($me) { return new PluginCheck($me->get('store.api'), $me->get('db'), $me->get('shopware.version')); }; $container['dummy.plugin.finder'] = function () { return new DummyPluginFinder(SW_PATH); }; $container['cleanup.files.finder'] = function () { return new CleanupFilesFinder(SW_PATH); }; $container['system.locker'] = function () { return new SystemLocker(SW_PATH . '/recovery/install/data/install.lock'); }; $container['controller.batch'] = function () use($me) { return new BatchController($me->get('slim.request'), $me->get('slim.response'), $me); }; $container['controller.requirements'] = function () use($me) { return new RequirementsController($me->get('slim.request'), $me->get('slim.response'), $me, $me->get('app')); }; $container['controller.cleanup'] = function () use($me) { return new CleanupController($me->get('slim.request'), $me->get('slim.response'), $me->get('dummy.plugin.finder'), $me->get('cleanup.files.finder'), $me->get('app'), SW_PATH); }; $container['shopware.container'] = function () use($me) { require_once SW_PATH . '/autoload.php'; $kernel = new \Shopware\Kernel('production', false); $kernel->boot(); $container = $kernel->getContainer(); $container->get('models')->generateAttributeModels(); return $container; }; $container['shopware.theme_installer'] = function ($c) { $shopwareContainer = $c['shopware.container']; /** @var $themeInstaller \Shopware\Components\Theme\Installer */ $themeInstaller = $shopwareContainer->get('theme_installer'); return $themeInstaller; }; }
} session_set_cookie_params(7200, $baseUrl); //Silence errors during session start, Work around session_start(): ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) @session_start(); @set_time_limit(0); $selectedLanguage = Utils::getLanguage($app->request, $lang); $language = (require __DIR__ . "/../data/lang/{$selectedLanguage}.php"); $clientIp = Utils::getRealIpAddr(); $app->view()->set('version', $container->get('shopware.version')); $app->view()->set('app', $app); $app->view()->set('clientIp', $clientIp); $app->view()->set('baseUrl', $baseUrl); $app->view()->set('language', $language); $app->view()->set('selectedLanguage', $selectedLanguage); $ipCheckEnabled = (bool) $app->config('check.ip'); if ($ipCheckEnabled && !Utils::isAllowed($clientIp)) { $app->view()->setData('filePath', UPDATE_PATH . '/' . 'allowed_ip.txt'); $app->render('noaccess.php'); $app->response()->status(403); $app->stop(); } // Redirect to "done" page if file cleanup was done if (false && isset($_SESSION['CLEANUP_DONE']) && $app->router()->getCurrentRoute()->getName() !== 'done') { $url = $app->urlFor('done'); $app->response()->redirect($url); } elseif (isset($_SESSION['DB_DONE']) && !isset($_SESSION['CLEANUP_DONE']) && $app->router()->getCurrentRoute()->getName() !== 'cleanup') { $url = $app->urlFor('cleanup'); $app->response()->redirect($url); } }); $app->error(function (Exception $e) use($app) {