/** Validates the uploads directory to ensure we're not going to inadvertently * put test uploads in the wrong place and/or delete production files. * * @param bool $force * * @return void */ protected function _assertTestUploadsDir($force = false) { if (!self::$_uploadsDirCheck or $force) { $this->_assertTestEnvironment(); $config = sfConfigHandler::replaceConstants(sfYaml::load($this->_getSettingsFilename())); /* Determine whether a the test uploads directory is different than the * production one. */ if (isset($config['prod']['.settings']['upload_dir'])) { $prod = $config['prod']['.settings']['upload_dir']; } elseif (isset($config['all']['.settings']['upload_dir'])) { $prod = $config['all']['.settings']['upload_dir']; } else { /* Get the default value: no good way to do this in Symfony 1.4. */ $prod = sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . 'uploads'; } $test = sfConfig::get('sf_test_dir'); if ($prod == $test) { self::_halt(sprintf('Please specify a *separate* test value for sf_upload_dir in %s.', $this->_getSettingsFilename())); } /* Check the directory itself to make sure it's valid. */ if (!file_exists($test)) { /* If it doesn't exist, let's see if we can't create it. */ if (!mkdir($test, 0777, true)) { self::_halt('Test upload directory (%s) does not exist. Please create this directory before continuing.', $test); } } elseif (!is_dir($test)) { self::_halt('Test upload directory (%s) not a directory.', $test); } if (!is_writable($test)) { self::_halt('Test upload directory (%s) is not writable.', $test); } self::$_uploadsDirCheck = true; } }