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.'); }
/** * Do the actual work. All child classes will need to implement this */ public function execute() { $file = $this->getArg(0); if ($file === 'php://output' || $file === 'php://stdout') { $this->mQuiet = true; } $handle = fopen($file, 'w'); if (!$handle) { $this->error("Failed to open {$file} for writing.\n", 1); } $exporter = new SiteExporter($handle); $sites = SiteSQLStore::newInstance()->getSites('recache'); $exporter->exportSites($sites); fclose($handle); $this->output("Exported sites to " . realpath($file) . ".\n"); }
/** * Do the actual work. All child classes will need to implement this */ public function execute() { $file = $this->getArg(0); if ($file === 'php://output' || $file === 'php://stdout') { $this->mQuiet = true; } $handle = fopen($file, 'w'); if (!$handle) { $this->error("Failed to open {$file} for writing.\n", 1); } $exporter = new SiteExporter($handle); $siteLookup = \MediaWiki\MediaWikiServices::getInstance()->getSiteLookup(); $exporter->exportSites($siteLookup->getSites()); fclose($handle); $this->output("Exported sites to " . realpath($file) . ".\n"); }
public function process() { if (!($remaining = $this->idsToProcess)) { $this->complete(); $this->isComplete = true; return; } if ($page = DataObject::get_by_id('SiteTree', array_shift($remaining))) { $exporter = new SiteExporter(); $exporter->customLinks = array($page->RelativeLink()); $exporter->root = $this->getRoot(); $exporter->theme = $this->theme; $exporter->baseUrl = $this->baseUrl; $exporter->makeRelative = $this->baseUrlType == 'rewrite'; $exporter->exportTo($this->tempDir); } $this->currentStep++; $this->idsToProcess = $remaining; if (!$remaining) { $this->complete(); $this->isComplete = true; } }
/** * @dataProvider provideRoundTrip() */ public function testRoundTrip(SiteList $sites) { $tmp = tmpfile(); $exporter = new SiteExporter($tmp); $exporter->exportSites($sites); fseek($tmp, 0); $xml = fread($tmp, 16 * 1024); $actualSites = new SiteList(); $store = $this->newSiteStore($actualSites); $importer = new SiteImporter($store); $importer->importFromXML($xml); $this->assertEquals($sites, $actualSites); }