/** * Returns the temporary folder that sapphire/silverstripe should use for its cache files * This is loaded into the TEMP_FOLDER define on start up * * @param $base The base path to use as the basis for the temp folder name. Defaults to BASE_PATH, * which is usually fine; however, the $base argument can be used to help test. */ function getTempFolder($base = null) { if (!$base) { $base = BASE_PATH; } if ($base) { $cachefolder = "silverstripe-cache" . str_replace(array(' ', "/", ":", "\\"), "-", $base); } else { $cachefolder = "silverstripe-cache"; } $ssTmp = $base . "/silverstripe-cache"; if (@file_exists($ssTmp)) { return $ssTmp; } $sysTmp = getSysTempDir(); $worked = true; $ssTmp = "{$sysTmp}/{$cachefolder}"; if (!@file_exists($ssTmp)) { @($worked = mkdir($ssTmp)); } if (!$worked) { $ssTmp = $base . "/silverstripe-cache"; $worked = true; if (!@file_exists($ssTmp)) { @($worked = mkdir($ssTmp)); } } if (!$worked) { user_error("Permission problem gaining access to a temp folder. " . "Please create a folder named silverstripe-cache in the base folder " . "of the installation and ensure it has the correct permissions", E_USER_ERROR); } return $ssTmp; }
public function tearDown() { parent::tearDown(); if (file_exists(getSysTempDir() . '/silverstripe-cacheC--inetpub-wwwroot-silverstripe')) { rmdir(getSysTempDir() . '/silverstripe-cacheC--inetpub-wwwroot-silverstripe'); } if (file_exists(getSysTempDir() . '/silverstripe-cache-Users-joebloggs-Sites-silverstripe')) { rmdir(getSysTempDir() . '/silverstripe-cache-Users-joebloggs-Sites-silverstripe'); } if (file_exists(getSysTempDir() . '/silverstripe-cache-var-www-silverstripe')) { rmdir(getSysTempDir() . '/silverstripe-cache-var-www-silverstripe'); } }
public function testGetTempPathInProject() { if (file_exists($this->tempPath)) { $this->assertEquals(getTempFolder(), $this->tempPath); } else { // A typical Windows location for where sites are stored on IIS $this->assertEquals(getTempFolder('C:\\inetpub\\wwwroot\\silverstripe'), getSysTempDir() . '/silverstripe-cacheC--inetpub-wwwroot-silverstripe'); // A typical Mac OS X location for where sites are stored $this->assertEquals(getTempFolder('/Users/joebloggs/Sites/silverstripe'), getSysTempDir() . '/silverstripe-cache-Users-joebloggs-Sites-silverstripe'); // A typical Linux location for where sites are stored $this->assertEquals(getTempFolder('/var/www/silverstripe'), getSysTempDir() . '/silverstripe-cache-var-www-silverstripe'); } }