Test is_writable recursively
public static isWritable ( string $directory, string[] $excludeDirectory = [] ) : boolean | ||
$directory | string | Directory start |
$excludeDirectory | string[] | Exclude directory |
return | boolean |
/** * Test * * @return void */ public function testIsWritableWithNotWritablePath() { $this->assertFalse($this->object->isWritable('/etc')); }
/** * Upgrade * * @return boolean */ public function upgrade() { $backupFilename = $this->getTmpPath() . '/backup.zip'; //Remove old backup if (file_exists($backupFilename)) { unlink($backupFilename); } if (File::isWritable(GC_APPLICATION_PATH, array(GC_APPLICATION_PATH . '/data/cache', GC_APPLICATION_PATH . '/.git'))) { if ($this->createBackup($backupFilename)) { foreach (array('library', 'module', 'vendor', 'tests') as $directory) { $this->addMessage(sprintf('Remove %s directory', GC_APPLICATION_PATH . '/' . $directory)); File::removeDirectory(GC_APPLICATION_PATH . '/' . $directory); } $directory = $this->getTmpPath() . '/v' . $this->getLatestVersion(); $this->addMessage(sprintf('Copy %s to %s', $directory, GC_APPLICATION_PATH)); File::copyDirectory($directory, GC_APPLICATION_PATH); $this->addMessage('Done!'); return true; } } $this->addMessage('Some files are not writable!'); $this->addMessage(sprintf('Please execute: chmod -R ug+rw %s', GC_APPLICATION_PATH)); return false; }
/** * Check configuration * * @return array */ public function checkConfigAction() { $this->checkInstall(3); if (!defined('PHP_VERSION_ID')) { $version = explode('.', PHP_VERSION); define('PHP_VERSION_ID', $version[0] * 10000 + $version[1] * 100 + $version[2]); } $serverData = array(); $serverData[] = array('label' => '/' . basename(GC_PUBLIC_PATH) . '/frontend', 'value' => File::isWritable(GC_PUBLIC_PATH . '/frontend')); $serverData[] = array('label' => '/config/autoload', 'value' => File::isWritable(GC_APPLICATION_PATH . '/config/autoload')); $serverData[] = array('label' => '/data/cache', 'value' => is_writable(GC_APPLICATION_PATH . '/data/cache')); $serverData[] = array('label' => '/templates/layout', 'value' => is_writable(GC_TEMPLATE_PATH . '/layout')); $serverData[] = array('label' => '/templates/view', 'value' => is_writable(GC_TEMPLATE_PATH . '/view')); $serverData[] = array('label' => '/templates/script', 'value' => is_writable(GC_TEMPLATE_PATH . '/script')); $serverData[] = array('label' => basename(GC_PUBLIC_PATH) . '/media', 'value' => File::isWritable(GC_MEDIA_PATH)); $phpData = array(); $phpData[] = array('label' => 'Php version >= 5.3.23', 'value' => PHP_VERSION_ID >= 50323); $phpData[] = array('label' => 'Xml', 'value' => extension_loaded('xml')); $phpData[] = array('label' => 'Fileinfo', 'value' => extension_loaded('fileinfo')); $phpData[] = array('label' => 'Pdo', 'value' => extension_loaded('pdo')); $phpData[] = array('label' => 'Database (Mysql, Pgsql)', 'value' => extension_loaded('pdo_mysql') or extension_loaded('pdo_pgsql')); $phpData[] = array('label' => 'Mbstring', 'value' => extension_loaded('mbstring')); $phpData[] = array('label' => 'Json', 'value' => function_exists('json_encode') and function_exists('json_decode')); $phpDirective = array(); $phpDirective[] = array('label' => 'Display Errors', 'needed' => false, 'value' => ini_get('display_errors') === true); $phpDirective[] = array('label' => 'File Uploads', 'needed' => true, 'value' => ini_get('file_uploads') === true); $phpDirective[] = array('label' => 'Magic Quotes Runtime', 'needed' => false, 'value' => ini_get('magic_quote_runtime') === true); $phpDirective[] = array('label' => 'Magic Quotes GPC', 'needed' => false, 'value' => ini_get('magic_quote_gpc') === true); $phpDirective[] = array('label' => 'Register Globals', 'needed' => false, 'value' => ini_get('register_globals') === true); $phpDirective[] = array('label' => 'Session Auto Start', 'needed' => false, 'value' => ini_get('session.auto_start') === true); if ($this->getRequest()->isPost()) { $continue = true; foreach (array($serverData, $phpData) as $configs) { foreach ($configs as $config) { if ($config['value'] !== true) { $continue = false; break 2; } } } if ($continue) { return $this->redirect()->toRoute('install/database'); } else { $this->flashMessenger()->addErrorMessage('All parameters must be set to "Yes"'); return $this->redirect()->toRoute('install/check-config'); } } $this->layout()->setVariables(array('currentRoute' => $this->getRouteMatch()->getMatchedRouteName())); return array('gitProject' => file_exists(GC_APPLICATION_PATH . '/.git'), 'phpData' => $phpData, 'phpDirective' => $phpDirective, 'serverData' => $serverData, 'cmsVersion' => Version::VERSION); }