public function writeTo($path)
 {
     Filesystem::makeFolder(dirname($path));
     if (is_dir(dirname($path))) {
         $this->writeImage($path);
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->logInWithPermission('ADMIN');
     // Save versioned state
     $this->oldReadingMode = Versioned::get_reading_mode();
     Versioned::set_stage(Versioned::DRAFT);
     // Set backend root to /UploadFieldTest
     AssetStoreTest_SpyStore::activate('UploadFieldTest');
     // Set the File Name Filter replacements so files have the expected names
     Config::inst()->update('SilverStripe\\Assets\\FileNameFilter', 'default_replacements', array('/\\s/' => '-', '/_/' => '-', '/[^A-Za-z0-9+.\\-]+/' => '', '/[\\-]{2,}/' => '-', '/^[\\.\\-_]+/' => ''));
     // Create a test folders for each of the fixture references
     foreach (Folder::get() as $folder) {
         $path = AssetStoreTest_SpyStore::getLocalPath($folder);
         Filesystem::makeFolder($path);
     }
     // Create a test files for each of the fixture references
     $files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder');
     foreach ($files as $file) {
         $path = AssetStoreTest_SpyStore::getLocalPath($file);
         Filesystem::makeFolder(dirname($path));
         $fh = fopen($path, "w+");
         fwrite($fh, str_repeat('x', 1000000));
         fclose($fh);
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->logInWithPermission('ADMIN');
     Versioned::set_stage(Versioned::DRAFT);
     // Set backend root to /AssetFieldTest
     AssetStoreTest_SpyStore::activate('AssetFieldTest');
     $create = function ($path) {
         Filesystem::makeFolder(dirname($path));
         $fh = fopen($path, "w+");
         fwrite($fh, str_repeat('x', 1000000));
         fclose($fh);
     };
     // Write all DBFile references
     foreach (AssetFieldTest_Object::get() as $object) {
         $path = AssetStoreTest_SpyStore::getLocalPath($object->File);
         $create($path);
     }
     // Create a test files for each of the fixture references
     $files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder');
     foreach ($files as $file) {
         $path = AssetStoreTest_SpyStore::getLocalPath($file);
         $create($path);
     }
 }
 public function tearDown()
 {
     if ($this->rootDir) {
         Filesystem::removeFolder($this->rootDir);
         $this->rootDir = null;
     }
     if ($this->originalServer) {
         $_SERVER = $this->originalServer;
         $this->originalServer = null;
     }
     parent::tearDown();
 }
 public function setUp()
 {
     parent::setUp();
     $this->alternateBasePath = $this->getCurrentAbsolutePath() . "/_fakewebroot";
     Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_folder', $this->alternateBasePath);
     $this->alternateBaseSavePath = TEMP_FOLDER . '/i18nTextCollectorTest_webroot';
     Filesystem::makeFolder($this->alternateBaseSavePath);
     // Push a class and template loader running from the fake webroot onto
     // the stack.
     $this->manifest = new ClassManifest($this->alternateBasePath, false, true, false);
     // Replace old template loader with new one with alternate base path
     $this->_oldLoader = ThemeResourceLoader::instance();
     ThemeResourceLoader::set_instance(new ThemeResourceLoader($this->alternateBasePath));
 }
 public function setUp()
 {
     parent::setUp();
     Versioned::set_stage(Versioned::DRAFT);
     // Set backend root to /DataDifferencerTest
     AssetStoreTest_SpyStore::activate('DataDifferencerTest');
     // Create a test files for each of the fixture references
     $files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder');
     foreach ($files as $file) {
         $fromPath = FRAMEWORK_PATH . '/tests/model/testimages/' . $file->Name;
         $destPath = AssetStoreTest_SpyStore::getLocalPath($file);
         // Only correct for test asset store
         Filesystem::makeFolder(dirname($destPath));
         copy($fromPath, $destPath);
     }
 }
 public function setUp()
 {
     parent::setUp();
     // Set backend root to /HTMLEditorFieldTest
     AssetStoreTest_SpyStore::activate('HTMLEditorFieldTest');
     // Set the File Name Filter replacements so files have the expected names
     Config::inst()->update('SilverStripe\\Assets\\FileNameFilter', 'default_replacements', array('/\\s/' => '-', '/_/' => '-', '/[^A-Za-z0-9+.\\-]+/' => '', '/[\\-]{2,}/' => '-', '/^[\\.\\-_]+/' => ''));
     // Create a test files for each of the fixture references
     $files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder');
     foreach ($files as $file) {
         $fromPath = FRAMEWORK_PATH . '/tests/forms/images/' . $file->Name;
         $destPath = AssetStoreTest_SpyStore::getLocalPath($file);
         // Only correct for test asset store
         Filesystem::makeFolder(dirname($destPath));
         copy($fromPath, $destPath);
     }
 }
 public function write($entities, $locale, $path)
 {
     // Create folder for lang files
     $langFolder = $path . '/lang';
     if (!file_exists($langFolder)) {
         Filesystem::makeFolder($langFolder);
         touch($langFolder . '/_manifest_exclude');
     }
     // Open the English file and write the Master String Table
     $langFile = $langFolder . '/' . $locale . '.yml';
     if ($fh = fopen($langFile, "w")) {
         fwrite($fh, $this->getYaml($entities, $locale));
         fclose($fh);
     } else {
         throw new LogicException("Cannot write language file! Please check permissions of {$langFile}");
     }
     return true;
 }
 public function setUp()
 {
     parent::setUp();
     // Set backend root to /ImageTest
     AssetStoreTest_SpyStore::activate('ProtectedFileControllerTest');
     // Create a test folders for each of the fixture references
     foreach (Folder::get() as $folder) {
         /** @var Folder $folder */
         $filePath = AssetStoreTest_SpyStore::getLocalPath($folder);
         Filesystem::makeFolder($filePath);
     }
     // Create a test files for each of the fixture references
     foreach (File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder') as $file) {
         /** @var File $file */
         $path = AssetStoreTest_SpyStore::getLocalPath($file);
         Filesystem::makeFolder(dirname($path));
         $fh = fopen($path, "w+");
         fwrite($fh, str_repeat('x', 1000000));
         fclose($fh);
         // Create variant for each file
         $this->getAssetStore()->setFromString(str_repeat('y', 100), $file->Filename, $file->Hash, 'variant');
     }
 }
 public function setUp()
 {
     parent::setUp();
     // Execute specific subclass
     if (get_class($this) == "ImageTest") {
         $this->markTestSkipped(sprintf('Skipping %s ', get_class($this)));
         return;
     }
     // Set backend root to /ImageTest
     AssetStoreTest_SpyStore::activate('ImageTest');
     // Copy test images for each of the fixture references
     $files = File::get()->exclude('ClassName', 'SilverStripe\\Assets\\Folder');
     foreach ($files as $image) {
         $filePath = AssetStoreTest_SpyStore::getLocalPath($image);
         // Only correct for test asset store
         $sourcePath = FRAMEWORK_PATH . '/tests/model/testimages/' . $image->Name;
         if (!file_exists($filePath)) {
             SSFilesystem::makeFolder(dirname($filePath));
             if (!copy($sourcePath, $filePath)) {
                 user_error('Failed to copy test images', E_USER_ERROR);
             }
         }
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->logInWithPermission('ADMIN');
     Versioned::set_stage(Versioned::DRAFT);
     // Set backend root to /ImageTest
     AssetStoreTest_SpyStore::activate('FileTest');
     // Create a test folders for each of the fixture references
     $folderIDs = $this->allFixtureIDs('SilverStripe\\Assets\\Folder');
     foreach ($folderIDs as $folderID) {
         $folder = DataObject::get_by_id('SilverStripe\\Assets\\Folder', $folderID);
         $filePath = ASSETS_PATH . '/FileTest/' . $folder->getFilename();
         Filesystem::makeFolder($filePath);
     }
     // Create a test files for each of the fixture references
     $fileIDs = $this->allFixtureIDs('SilverStripe\\Assets\\File');
     foreach ($fileIDs as $fileID) {
         /** @var File $file */
         $file = DataObject::get_by_id('SilverStripe\\Assets\\File', $fileID);
         $root = ASSETS_PATH . '/FileTest/';
         if ($folder = $file->Parent()) {
             $root .= $folder->getFilename();
         }
         $path = $root . substr($file->getHash(), 0, 10) . '/' . basename($file->getFilename());
         Filesystem::makeFolder(dirname($path));
         $fh = fopen($path, "w+");
         fwrite($fh, str_repeat('x', 1000000));
         fclose($fh);
     }
     // Conditional fixture creation in case the 'cms' module is installed
     if (class_exists('SilverStripe\\CMS\\Model\\ErrorPage')) {
         $page = new ErrorPage(array('Title' => 'Page not Found', 'ErrorCode' => 404));
         $page->write();
         $page->copyVersionToStage('Stage', 'Live');
     }
 }
 /**
  * Reset defaults for this store
  */
 public static function reset()
 {
     // Remove all files in this store
     if (self::$basedir) {
         $path = self::base_path();
         if (file_exists($path)) {
             SSFilesystem::removeFolder($path);
         }
     }
     self::$seekable_override = null;
     self::$basedir = null;
 }
 public function writeTo($filename)
 {
     if (!$filename) {
         return;
     }
     // Get current image data
     if (file_exists($filename)) {
         list($width, $height, $type, $attr) = getimagesize($filename);
         unlink($filename);
     } else {
         Filesystem::makeFolder(dirname($filename));
     }
     // If image type isn't known, guess from extension
     $ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
     if (empty($type)) {
         switch ($ext) {
             case "gif":
                 $type = IMAGETYPE_GIF;
                 break;
             case "jpeg":
             case "jpg":
             case "jpe":
                 $type = IMAGETYPE_JPEG;
                 break;
             default:
                 $type = IMAGETYPE_PNG;
                 break;
         }
     }
     // if $this->interlace != 0, the output image will be interlaced
     imageinterlace($this->gd, $this->interlace);
     // if the extension does not exist, the file will not be created!
     switch ($type) {
         case IMAGETYPE_GIF:
             imagegif($this->gd, $filename);
             break;
         case IMAGETYPE_JPEG:
             imagejpeg($this->gd, $filename, $this->quality);
             break;
             // case 3, and everything else
         // case 3, and everything else
         default:
             // Save them as 8-bit images
             // imagetruecolortopalette($this->gd, false, 256);
             imagepng($this->gd, $filename);
             break;
     }
     if (file_exists($filename)) {
         @chmod($filename, 0664);
     }
 }
 /**
  * Return the most recent modification time of anything in the folder.
  *
  * @param string $folder The folder, relative to the site root
  * @param array $extensionList An option array of file extensions to limit the search to
  * @return string Same as filemtime() format.
  */
 public static function folderModTime($folder, $extensionList = null)
 {
     $modTime = 0;
     if (!Filesystem::isAbsolute($folder)) {
         $folder = Director::baseFolder() . '/' . $folder;
     }
     $items = scandir($folder);
     foreach ($items as $item) {
         if ($item[0] != '.') {
             // Recurse into folders
             if (is_dir("{$folder}/{$item}")) {
                 $modTime = max($modTime, self::folderModTime("{$folder}/{$item}", $extensionList));
                 // Check files
             } else {
                 $extension = null;
                 if ($extensionList) {
                     $extension = strtolower(substr($item, strrpos($item, '.') + 1));
                 }
                 if (!$extensionList || in_array($extension, $extensionList)) {
                     $modTime = max($modTime, filemtime("{$folder}/{$item}"));
                 }
             }
         }
     }
     //if(!$recursiveCall) self::$cache_folderModTime[$cacheID] = $modTime;
     return $modTime;
 }