silverstripe-staticpublisher/code/tasks/StaticExporterTask.php

42 lines
1.1 KiB
PHP
Raw Normal View History

2012-09-21 07:47:26 +02:00
<?php
2012-09-21 07:47:26 +02:00
/**
2012-09-25 10:02:26 +02:00
* @package staticpublisher
2012-09-21 07:47:26 +02:00
*/
2015-12-20 05:19:24 +01:00
class StaticExporterTask extends BuildTask
{
2012-09-21 07:47:26 +02:00
2015-12-20 05:19:24 +01:00
public function run($request)
{
$now = microtime(true);
$export = new StaticExporter();
2012-09-21 07:47:26 +02:00
2015-12-20 05:19:24 +01:00
$url = $request->getVar('baseurl');
$sym = $request->getVar('symlink');
$quiet = $request->getVar('quiet');
$folder = $request->getVar('path');
2012-09-21 07:47:26 +02:00
2015-12-20 05:19:24 +01:00
if (!$folder) {
$folder = TEMP_FOLDER . '/static-export';
}
2012-09-21 07:47:26 +02:00
2015-12-20 05:19:24 +01:00
$url = ($url) ? $url : Director::baseURL();
$symlink = ($sym != "false");
$quiet = ($quiet) ? $quiet : false;
2012-09-21 07:47:26 +02:00
2015-12-20 05:19:24 +01:00
if (!$quiet) {
printf("Exporting website with %s base URL... %s", $url, PHP_EOL);
}
$path = $export->doExport($url, $folder, $symlink, $quiet);
2012-09-21 07:47:26 +02:00
2015-12-20 05:19:24 +01:00
if (!$quiet) {
printf("\nWebsite exported to %s\nTotal time %s\nMemory used %s. %s",
$path,
number_format(microtime(true) - $now, 2) . 's',
number_format(memory_get_peak_usage() / 1024 / 1024, 2) .'mb',
PHP_EOL
);
}
}
}