Beispiel #1
2
 function generatePDF()
 {
     // tempfolder
     $tmpBaseFolder = TEMP_FOLDER . '/shopsystem';
     $tmpFolder = project() ? "{$tmpBaseFolder}/" . project() : "{$tmpBaseFolder}/site";
     if (is_dir($tmpFolder)) {
         Filesystem::removeFolder($tmpFolder);
     }
     if (!file_exists($tmpFolder)) {
         Filesystem::makeFolder($tmpFolder);
     }
     $baseFolderName = basename($tmpFolder);
     //Get site
     Requirements::clear();
     $link = Director::absoluteURL($this->pdfLink() . "/?view=1");
     $response = Director::test($link);
     $content = $response->getBody();
     $content = utf8_decode($content);
     $contentfile = "{$tmpFolder}/" . $this->PublicURL . ".html";
     if (!file_exists($contentfile)) {
         // Write to file
         if ($fh = fopen($contentfile, 'w')) {
             fwrite($fh, $content);
             fclose($fh);
         }
     }
     return $contentfile;
 }
 public function tearDown()
 {
     AssetStoreTest_SpyStore::reset();
     SS_Filesystem::removeFolder($this->getBasePath());
     parent::tearDown();
     Config::unnest();
 }
 /**
  * Rebuilds the static cache for the pages passed through via $urls
  * @param array $urls The URLs of pages to re-fetch and cache.
  */
 function rebuildCache($urls, $removeAll = true)
 {
     if (!is_array($urls)) {
         return;
     }
     // $urls must be an array
     if (!Director::is_cli()) {
         echo "<pre>\n";
     }
     echo "Rebuilding cache.\nNOTE: Please ensure that this page ends with 'Done!' - if not, then something may have gone wrong.\n\n";
     $page = singleton('Page');
     foreach ($urls as $i => $url) {
         $url = Director::makeRelative($url);
         if (substr($url, -1) == '/') {
             $url = substr($url, 0, -1);
         }
         $urls[$i] = $url;
     }
     $urls = array_unique($urls);
     if ($removeAll && file_exists("../cache")) {
         echo "Removing old cache... \n";
         flush();
         Filesystem::removeFolder("../cache", true);
         echo "done.\n\n";
     }
     echo "Republishing " . sizeof($urls) . " urls...\n\n";
     $page->publishPages($urls);
     echo "\n\n== Done! ==";
 }
 /**
  * Completes the job by zipping up the generated export and creating an
  * export record for it.
  */
 protected function complete()
 {
     $siteTitle = SiteConfig::current_site_config()->Title;
     $filename = preg_replace('/[^a-zA-Z0-9-.+]/', '-', sprintf('%s-%s.zip', $siteTitle, date('c')));
     $dir = Folder::findOrMake(SiteExportExtension::EXPORTS_DIR);
     $dirname = ASSETS_PATH . '/' . SiteExportExtension::EXPORTS_DIR;
     $pathname = "{$dirname}/{$filename}";
     SiteExportUtils::zip_directory($this->tempDir, "{$dirname}/{$filename}");
     Filesystem::removeFolder($this->tempDir);
     $file = new File();
     $file->ParentID = $dir->ID;
     $file->Title = $siteTitle . ' ' . date('c');
     $file->Filename = $dir->Filename . $filename;
     $file->write();
     $export = new SiteExport();
     $export->ParentClass = $this->rootClass;
     $export->ParentID = $this->rootId;
     $export->Theme = $this->theme;
     $export->BaseUrlType = ucfirst($this->baseUrlType);
     $export->BaseUrl = $this->baseUrl;
     $export->ArchiveID = $file->ID;
     $export->write();
     if ($this->email) {
         $email = new Email();
         $email->setTo($this->email);
         $email->setTemplate('SiteExportCompleteEmail');
         $email->setSubject(sprintf('Site Export For "%s" Complete', $siteTitle));
         $email->populateTemplate(array('SiteTitle' => $siteTitle, 'Link' => $file->getAbsoluteURL()));
         $email->send();
     }
 }
 public function tearDown()
 {
     SecurityToken::enable();
     $this->folder->deleteDatabaseOnly();
     Filesystem::removeFolder($this->folder->getFullPath());
     parent::tearDown();
 }
Beispiel #6
0
 public function tearDown()
 {
     if ($this->origBackend) {
         Image::set_backend($this->origBackend);
     }
     // Remove the test files that we've created
     $fileIDs = $this->allFixtureIDs('Image');
     foreach ($fileIDs as $fileID) {
         $file = DataObject::get_by_id('Image', $fileID);
         if ($file && file_exists(BASE_PATH . "/{$file->Filename}")) {
             unlink(BASE_PATH . "/{$file->Filename}");
         }
     }
     // Remove the test folders that we've created
     $folderIDs = $this->allFixtureIDs('Folder');
     foreach ($folderIDs as $folderID) {
         $folder = DataObject::get_by_id('Folder', $folderID);
         if ($folder && file_exists(BASE_PATH . "/{$folder->Filename}")) {
             Filesystem::removeFolder(BASE_PATH . "/{$folder->Filename}");
         }
         if ($folder && file_exists(BASE_PATH . "/" . $folder->Filename . "_resampled")) {
             Filesystem::removeFolder(BASE_PATH . "/" . $folder->Filename . "_resampled");
         }
     }
     parent::tearDown();
 }
Beispiel #7
0
 public function tearDown()
 {
     parent::tearDown();
     ErrorPage::config()->static_filepath = $this->orig['ErrorPage_staticfilepath'];
     Filesystem::removeFolder($this->tmpAssetsPath . '/ErrorPageTest');
     Filesystem::removeFolder($this->tmpAssetsPath);
     Config::inst()->update('Director', 'environment_type', $this->origEnvType);
 }
 function tearDown()
 {
     parent::tearDown();
     ErrorPage::set_static_filepath($this->orig['ErrorPage_staticfilepath']);
     Director::set_environment_type($this->orig['Director_environmenttype']);
     Filesystem::removeFolder($this->tmpAssetsPath . '/ErrorPageTest');
     Filesystem::removeFolder($this->tmpAssetsPath);
 }
 function tearDown()
 {
     unlink($this->img1->getFullPath());
     unlink($this->img2->getFullPath());
     // Remove the assets/ folder if it was created during {@link self::setUp()}
     if ($this->createdAssetsFolder) {
         Filesystem::removeFolder(ASSETS_PATH);
     }
 }
 function tearDown()
 {
     parent::tearDown();
     Object::remove_extension("SiteTree", "FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
     FilesystemPublisher::$domain_based_caching = $this->orig['domain_based_caching'];
     if (file_exists(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder')) {
         Filesystem::removeFolder(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder');
     }
 }
 public function tearDown()
 {
     parent::tearDown();
     SiteTree::remove_extension("FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
     Config::inst()->update('FilesystemPublisher', 'domain_based_caching', $this->orig['domain_based_caching']);
     if (file_exists(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder')) {
         Filesystem::removeFolder(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder');
     }
 }
Beispiel #12
0
 public function tearDown()
 {
     Injector::unnest();
     SS_Datetime::clear_mock_now();
     if ($this->envPath) {
         Filesystem::removeFolder($this->envPath);
         $this->envPath = null;
     }
     parent::tearDown();
 }
 public function tearDown()
 {
     parent::tearDown();
     Config::inst()->unnest();
     SiteTree::remove_extension("FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')");
     if (file_exists(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder')) {
         Filesystem::removeFolder(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder');
     }
     // Purge DB from StaticPagesQueue items.
     self::empty_temp_db();
 }
 public function tearDown()
 {
     if ($this->rootDir) {
         Filesystem::removeFolder($this->rootDir);
         $this->rootDir = null;
     }
     if ($this->originalServer) {
         $_SERVER = $this->originalServer;
         $this->originalServer = null;
     }
     parent::tearDown();
 }
Beispiel #15
0
 function export()
 {
     if ($_REQUEST['baseurl']) {
         $base = $_REQUEST['baseurl'];
         if (substr($base, -1) != '/') {
             $base .= '/';
         }
         Director::setBaseURL($base);
     }
     $folder = '/tmp/static-export/' . project();
     if (!project()) {
         $folder .= 'site';
     }
     if (!file_exists($folder)) {
         mkdir($folder, Filesystem::$folder_create_mask, true);
     }
     $f1 = Director::baseFolder() . '/assets';
     $f2 = Director::baseFolder() . '/' . project();
     `cd {$folder}; ln -s {$f1}; ln -s {$f2}`;
     $baseFolder = basename($folder);
     if ($folder && file_exists($folder)) {
         $pages = DataObject::get("SiteTree");
         foreach ($pages as $page) {
             $subfolder = "{$folder}/{$page->URLSegment}";
             $contentfile = "{$folder}/{$page->URLSegment}/index.html";
             // Make the folder
             if (!file_exists($subfolder)) {
                 mkdir($subfolder, Filesystem::$folder_create_mask);
             }
             // Run the page
             Requirements::clear();
             $controllerClass = "{$page->class}_Controller";
             if (class_exists($controllerClass)) {
                 $controller = new $controllerClass($page);
                 $pageContent = $controller->run(array());
                 // Write to file
                 if ($fh = fopen($contentfile, 'w')) {
                     fwrite($fh, $pageContent->getBody());
                     fclose($fh);
                 }
             }
         }
         copy("{$folder}/home/index.html", "{$folder}/index.html");
         `cd /tmp/static-export; tar -czhf {$baseFolder}.tar.gz {$baseFolder}`;
         $content = file_get_contents("/tmp/static-export/{$baseFolder}.tar.gz");
         Filesystem::removeFolder('/tmp/static-export');
         HTTP::sendFileToBrowser($content, "{$baseFolder}.tar.gz");
         return null;
     } else {
         echo _t('StaticExporter.ONETHATEXISTS', "Please specify a folder that exists");
     }
 }
Beispiel #16
0
 function export()
 {
     // specify custom baseurl for publishing to other webroot
     if (isset($_REQUEST['baseurl'])) {
         $base = $_REQUEST['baseurl'];
         if (substr($base, -1) != '/') {
             $base .= '/';
         }
         Director::setBaseURL($base);
     }
     // setup temporary folders
     $tmpBaseFolder = TEMP_FOLDER . '/static-export';
     $tmpFolder = project() ? "{$tmpBaseFolder}/" . project() : "{$tmpBaseFolder}/site";
     if (!file_exists($tmpFolder)) {
         Filesystem::makeFolder($tmpFolder);
     }
     $baseFolderName = basename($tmpFolder);
     // symlink /assets
     $f1 = ASSETS_PATH;
     $f2 = Director::baseFolder() . '/' . project();
     `cd {$tmpFolder}; ln -s {$f1}; ln -s {$f2}`;
     // iterate through all instances of SiteTree
     $pages = DataObject::get("SiteTree");
     foreach ($pages as $page) {
         $subfolder = "{$tmpFolder}/{$page->URLSegment}";
         $contentfile = "{$tmpFolder}/{$page->URLSegment}/index.html";
         // Make the folder
         if (!file_exists($subfolder)) {
             Filesystem::makeFolder($subfolder);
         }
         // Run the page
         Requirements::clear();
         $link = Director::makeRelative($page->Link());
         $response = Director::test($link);
         // Write to file
         if ($fh = fopen($contentfile, 'w')) {
             fwrite($fh, $response->getBody());
             fclose($fh);
         }
     }
     // copy homepage (URLSegment: "home") to webroot
     copy("{$tmpFolder}/home/index.html", "{$tmpFolder}/index.html");
     // archive all generated files
     `cd {$tmpBaseFolder}; tar -czhf {$baseFolderName}.tar.gz {$baseFolderName}`;
     $archiveContent = file_get_contents("{$tmpBaseFolder}/{$baseFolderName}.tar.gz");
     // remove temporary files and folder
     Filesystem::removeFolder($tmpBaseFolder);
     // return as download to the client
     $response = HTTPRequest::send_file($archiveContent, "{$baseFolderName}.tar.gz", 'application/x-tar-gz');
     echo $response->output();
 }
 public function testSiteExporterGeneratesHtmlAndAssets()
 {
     $suffix = 0;
     while (is_dir($path = TEMP_FOLDER . '/' . __CLASS__ . $suffix)) {
         $suffix++;
     }
     $expect = array('index.html', 'about.html', 'about/staff.html', 'about/history.html', 'contact.html');
     $exporter = new SiteExporter();
     $exporter->exportTo($path);
     foreach ($expect as $file) {
         $this->assertFileExists("{$path}/{$file}");
     }
     Filesystem::removeFolder($path);
 }
 public function doExport($data, $form)
 {
     $data = $form->getData();
     $links = array();
     $siteTitle = SiteConfig::current_site_config()->Title;
     // If the queued jobs module is installed, then queue up an export
     // job rather than performing the export.
     if (class_exists('QueuedJobService')) {
         $job = new SiteExportJob($form->getRecord());
         $job->theme = $data['ExportSiteTheme'];
         $job->baseUrl = $data['ExportSiteBaseUrl'];
         $job->baseUrlType = $data['ExportSiteBaseUrlType'];
         $job->email = $data['ExportSiteCompleteEmail'];
         singleton('QueuedJobService')->queueJob($job);
         return new SS_HTTPResponse($form->dataFieldByName('SiteExports')->FieldHolder(), 200, 'The site export job has been queued.');
     }
     // First generate a temp directory to store the export content in.
     $temp = TEMP_FOLDER;
     $temp .= sprintf('/siteexport_%s', date('Y-m-d-His'));
     mkdir($temp);
     $exporter = new SiteExporter();
     $exporter->root = $form->getRecord();
     $exporter->theme = $data['ExportSiteTheme'];
     $exporter->baseUrl = $data['ExportSiteBaseUrl'];
     $exporter->makeRelative = $data['ExportSiteBaseUrlType'] == 'rewrite';
     $exporter->exportTo($temp);
     // Then place the exported content into an archive, stored in the assets
     // root, and create a site export for it.
     $filename = preg_replace('/[^a-zA-Z0-9-.+]/', '-', sprintf('%s-%s.zip', $siteTitle, date('c')));
     $dir = Folder::findOrMake(self::EXPORTS_DIR);
     $dirname = ASSETS_PATH . '/' . self::EXPORTS_DIR;
     $pathname = "{$dirname}/{$filename}";
     SiteExportUtils::zip_directory($temp, "{$dirname}/{$filename}");
     Filesystem::removeFolder($temp);
     $file = new File();
     $file->ParentID = $dir->ID;
     $file->Title = $siteTitle . ' ' . date('c');
     $file->Filename = $dir->Filename . $filename;
     $file->write();
     $export = new SiteExport();
     $export->ParentClass = $form->getRecord()->class;
     $export->ParentID = $form->getRecord()->ID;
     $export->Theme = SSViewer::current_theme();
     $export->BaseUrlType = ucfirst($data['ExportSiteBaseUrlType']);
     $export->BaseUrl = $data['ExportSiteBaseUrl'];
     $export->ArchiveID = $file->ID;
     $export->write();
     return new SS_HTTPResponse($form->dataFieldByName('SiteExports')->FieldHolder(), 200, 'The site export has been generated.');
 }
 public function testListFolder()
 {
     if (file_exists($this->testDir)) {
         Filesystem::removeFolder($this->testDir);
     }
     mkdir($this->testDir);
     file_put_contents($this->testDir . '/testfile.txt', 'dummy_data');
     $reader = $this->contentService->getReader('File:||' . $this->testDir);
     $list = $reader->getList();
     $this->assertEquals(1, count($list));
     $file = $list[0];
     $writer = $file->getWriter();
     $writer->write('new contents');
     $this->assertEquals('new contents', file_get_contents($this->testDir . '/testfile.txt'));
 }
 public function testClearThousands()
 {
     Filesystem::removeFolder(TEMP_FOLDER . '/my_test_cache');
     $cache = new SimpleCache(new SimpleFileBasedCacheStore(TEMP_FOLDER . '/my_test_cache'));
     for ($i = 0; $i < 1000; $i++) {
         $object = new stdClass();
         $object->Title = "Object {$i}";
         $other = $i % 10;
         $cache->store('key_' . $i, $object, -1, array('mytag', "mod{$other}"));
     }
     $start = microtime(true);
     $cache->deleteByTag('mytag');
     $end = microtime(true) - $start;
     $elems = $cache->getByTag('mytag');
     $this->assertEquals(0, count($elems));
 }
 public function onBeforeDelete()
 {
     // A workaround for that fact that Folder::onBeforeDelete() only removes
     // the folder if only a _resampled dir exists. If the folder is empty
     // and only has _resampled and _versions directories then delete it.
     if ($this->owner->Filename && is_dir($this->owner->getFullPath())) {
         $items = scandir($this->owner->getFullPath());
         $versionsDir = FileVersion::VERSION_FOLDER;
         // Remove . and .. items.
         array_shift($items);
         array_shift($items);
         $delete = count($items) == 1 && $items[0] == $versionsDir || count($items) == 2 && $items == array('_resampled', $versionsDir);
         if ($delete) {
             Filesystem::removeFolder($this->owner->getFullPath());
         }
     }
 }
Beispiel #22
0
	function tearDown() {
		/* Remove the test files that we've created */
		$fileIDs = $this->allFixtureIDs('Image');
		foreach($fileIDs as $fileID) {
			$file = DataObject::get_by_id('Image', $fileID);
			if($file && file_exists(BASE_PATH."/$file->Filename")) unlink(BASE_PATH."/$file->Filename");
		}

		/* Remove the test folders that we've crated */
		$folderIDs = $this->allFixtureIDs('Folder');
		foreach($folderIDs as $folderID) {
			$folder = DataObject::get_by_id('Folder', $folderID);
			if($folder && file_exists(BASE_PATH."/$folder->Filename")) Filesystem::removeFolder(BASE_PATH."/$folder->Filename");
		}
		
		parent::tearDown();
	}
Beispiel #23
0
 public function testAvailableThemes()
 {
     $config = $this->objFromFixture('SiteConfig', 'default');
     $ds = DIRECTORY_SEPARATOR;
     $testThemeBaseDir = TEMP_FOLDER . $ds . 'test-themes';
     if (file_exists($testThemeBaseDir)) {
         Filesystem::removeFolder($testThemeBaseDir);
     }
     mkdir($testThemeBaseDir);
     mkdir($testThemeBaseDir . $ds . 'blackcandy');
     mkdir($testThemeBaseDir . $ds . 'blackcandy_blog');
     mkdir($testThemeBaseDir . $ds . 'darkshades');
     mkdir($testThemeBaseDir . $ds . 'darkshades_blog');
     $themes = $config->getAvailableThemes($testThemeBaseDir);
     $this->assertContains('blackcandy', $themes, 'Test themes contain blackcandy theme');
     $this->assertContains('darkshades', $themes, 'Test themes contain darkshades theme');
     SiteConfig::config()->disabled_themes = array('darkshades');
     $themes = $config->getAvailableThemes($testThemeBaseDir);
     $this->assertFalse(in_array('darkshades', $themes), 'Darkshades was disabled - it is no longer available');
     Filesystem::removeFolder($testThemeBaseDir);
 }
 public function tearDown()
 {
     parent::tearDown();
     // Remove the test files that we've created
     $fileIDs = $this->allFixtureIDs('File');
     foreach ($fileIDs as $fileID) {
         $file = DataObject::get_by_id('File', $fileID);
         if ($file && file_exists(BASE_PATH . "/{$file->Filename}")) {
             unlink(BASE_PATH . "/{$file->Filename}");
         }
     }
     // Remove the test folders that we've crated
     $folderIDs = $this->allFixtureIDs('Folder');
     foreach ($folderIDs as $folderID) {
         $folder = DataObject::get_by_id('Folder', $folderID);
         if ($folder && file_exists(BASE_PATH . "/{$folder->Filename}")) {
             Filesystem::removeFolder(BASE_PATH . "/{$folder->Filename}");
         }
     }
     // Remove left over folders and any files that may exist
     if (file_exists(ASSETS_PATH . '/ChartTest')) {
         Filesystem::removeFolder(ASSETS_PATH . '/ChartTest');
     }
 }
 public function tearDown()
 {
     parent::tearDown();
     /* Remove the test files that we've created */
     $fileIDs = $this->allFixtureIDs('File');
     foreach ($fileIDs as $fileID) {
         $file = DataObject::get_by_id('File', $fileID);
         if ($file && file_exists(BASE_PATH . "/{$file->Filename}")) {
             unlink(BASE_PATH . "/{$file->Filename}");
         }
     }
     /* Remove the test folders that we've crated */
     $folderIDs = $this->allFixtureIDs('Folder');
     foreach ($folderIDs as $folderID) {
         $folder = DataObject::get_by_id('Folder', $folderID);
         if ($folder && file_exists(BASE_PATH . "/{$folder->Filename}")) {
             Filesystem::removeFolder(BASE_PATH . "/{$folder->Filename}");
         }
     }
     // Remove left over folders and any files that may exist
     if (file_exists('../assets/FileTest')) {
         Filesystem::removeFolder('../assets/FileTest');
     }
     if (file_exists('../assets/FileTest-subfolder')) {
         Filesystem::removeFolder('../assets/FileTest-subfolder');
     }
     if (file_exists('../assets/FileTest.txt')) {
         unlink('../assets/FileTest.txt');
     }
     if (file_exists("../assets/FileTest-folder-renamed1")) {
         Filesystem::removeFolder("../assets/FileTest-folder-renamed1");
     }
     if (file_exists("../assets/FileTest-folder-renamed2")) {
         Filesystem::removeFolder("../assets/FileTest-folder-renamed2");
     }
     if (file_exists("../assets/FileTest-folder-renamed3")) {
         Filesystem::removeFolder("../assets/FileTest-folder-renamed3");
     }
 }
 /**
  * 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)) {
             \Filesystem::removeFolder($path);
         }
     }
     self::$seekable_override = null;
     self::$basedir = null;
 }
 public function tearDown()
 {
     parent::tearDown();
     Filesystem::removeFolder($this->envPath);
 }
 /**
  * Delete any created files and folders from assets directory
  *
  * @AfterScenario @assets
  */
 public function cleanAssetsAfterScenario(ScenarioEvent $event)
 {
     foreach (\File::get() as $file) {
         $file->delete();
     }
     \Filesystem::removeFolder(ASSETS_PATH, true);
 }
 public function tearDown()
 {
     if ($this->tempPath) {
         Filesystem::removeFolder($this->tempPath);
     }
 }
Beispiel #30
0
	function onBeforeDelete() {
		if($this->ID && ($children = $this->AllChildren())) {
			foreach($children as $child) {
				if(!$this->Filename || !$this->Name || !file_exists($this->getFullPath())) {
					$child->setField('Name',null);
					$child->Filename = null;
				}
				$child->delete();
			}
		}

		// Do this after so a folder's contents are removed before we delete the folder.
		if($this->Filename && $this->Name && file_exists($this->getFullPath())) {
			$files = glob( $this->getFullPath() . '/*' );
			
			if( !$files || ( count( $files ) == 1 && preg_match( '/\/_resampled$/', $files[0] ) ) )
				Filesystem::removeFolder( $this->getFullPath() );
		}
		
		parent::onBeforeDelete();
	}