From 0545d8abdd66a8674f86b2e39fabdc3ed4f0c782 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Mon, 15 Jan 2018 12:05:19 +1300 Subject: [PATCH 01/14] API Add namespaces, optimise imports, separate classes and apply PSR-2 syntax --- .../UserFormUseQueuedExportExtension.php | 23 +++- {code => src}/GenerateCSVJob.php | 96 ++++++++----- {code => src}/GridFieldQueuedExportButton.php | 129 +++++++++++------- src/GridFieldQueuedExportButton_Response.php | 26 ++++ .../GridFieldQueuedExportButton.ss | 0 tests/GenerateCSVJobTest.php | 70 +++------- tests/GenerateCSVJobTest_Controller.php | 40 ++++++ tests/GenerateCSVJobTest_Record.php | 28 ++++ 8 files changed, 274 insertions(+), 138 deletions(-) rename {code/extensions => src/Extensions}/UserFormUseQueuedExportExtension.php (50%) rename {code => src}/GenerateCSVJob.php (77%) rename {code => src}/GridFieldQueuedExportButton.php (66%) create mode 100644 src/GridFieldQueuedExportButton_Response.php rename {code/templates => templates}/GridFieldQueuedExportButton.ss (100%) create mode 100644 tests/GenerateCSVJobTest_Controller.php create mode 100644 tests/GenerateCSVJobTest_Record.php diff --git a/code/extensions/UserFormUseQueuedExportExtension.php b/src/Extensions/UserFormUseQueuedExportExtension.php similarity index 50% rename from code/extensions/UserFormUseQueuedExportExtension.php rename to src/Extensions/UserFormUseQueuedExportExtension.php index abd3694..f9d3746 100644 --- a/code/extensions/UserFormUseQueuedExportExtension.php +++ b/src/Extensions/UserFormUseQueuedExportExtension.php @@ -1,20 +1,29 @@ fieldByName('Root.Submissions.Submissions'); $config = $gridField->getConfig(); - $oldExportButton = $config->getComponentByType('GridFieldExportButton'); + $oldExportButton = $config->getComponentByType(GridFieldExportButton::class); $config->addComponent($newExportButton = new GridFieldQueuedExportButton('buttons-after-left')); - + // Set Header and Export columns on new Export Button - $newExportButton->setCsvHasHeader($oldExportButton->getCsvHasHeader()); + $newExportButton->setCsvHasHeader($oldExportButton->getCsvHasHeader()); $newExportButton->setExportColumns($oldExportButton->getExportColumns()); - - $config->removeComponentsByType('GridFieldExportButton'); + + $config->removeComponentsByType(GridFieldExportButton::class); } } diff --git a/code/GenerateCSVJob.php b/src/GenerateCSVJob.php similarity index 77% rename from code/GenerateCSVJob.php rename to src/GenerateCSVJob.php index 2a81e51..36aad98 100644 --- a/code/GenerateCSVJob.php +++ b/src/GenerateCSVJob.php @@ -1,5 +1,19 @@ ID = Injector::inst()->create('RandomGenerator')->randomToken('sha1'); + public function __construct() + { + $this->ID = Injector::inst()->create(RandomGenerator::class)->randomToken('sha1'); $this->Seperator = ','; $this->IncludeHeader = true; $this->HeadersOutput = false; @@ -26,27 +42,32 @@ public function __construct() { /** * @return string */ - public function getJobType() { + public function getJobType() + { return QueuedJob::QUEUED; } /** * @return string */ - public function getTitle() { + public function getTitle() + { return "Export a CSV of a Gridfield"; } /** * @return string */ - public function getSignature() { + public function getSignature() + { return md5(get_class($this) . '-' . $this->ID); } + /** * @param GridField $gridField */ - function setGridField(GridField $gridField) { + function setGridField(GridField $gridField) + { $this->GridFieldName = $gridField->getName(); $this->GridFieldURL = $gridField->Link(); } @@ -54,7 +75,8 @@ function setGridField(GridField $gridField) { /** * @param $session */ - function setSession($session) { + function setSession($session) + { // None of the gridfield actions are needed, and they make the stored session bigger, so pull // them out. $actionkeys = array_filter(array_keys($session), function ($i) { @@ -69,21 +91,27 @@ function setSession($session) { $this->Session = $session; } - function setColumns($columns) { + function setColumns($columns) + { $this->Columns = $columns; } - function setSeparator($seperator) { + function setSeparator($seperator) + { $this->Separator = $seperator; } - function setIncludeHeader($includeHeader) { + function setIncludeHeader($includeHeader) + { $this->IncludeHeader = $includeHeader; } - protected function getOutputPath() { + protected function getOutputPath() + { $base = ASSETS_PATH . '/.exports'; - if (!is_dir($base)) mkdir($base, 0770, true); + if (!is_dir($base)) { + mkdir($base, 0770, true); + } // Although the string is random, so should be hard to guess, also try and block access directly. // Only works in Apache though @@ -91,24 +119,27 @@ protected function getOutputPath() { file_put_contents("$base/.htaccess", "Deny from all\nRewriteRule .* - [F]\n"); } - $folder = $base.'/'.$this->getSignature(); - if (!is_dir($folder)) mkdir($folder, 0770, true); + $folder = $base . '/' . $this->getSignature(); + if (!is_dir($folder)) { + mkdir($folder, 0770, true); + } - return $folder.'/'.$this->getSignature().'.csv'; + return $folder . '/' . $this->getSignature() . '.csv'; } /** * @return GridField * @throws SS_HTTPResponse_Exception */ - protected function getGridField() { + protected function getGridField() + { $session = $this->Session; // Store state in session, and pass ID to client side. $state = array( - 'grid' => $this->GridFieldName, + 'grid' => $this->GridFieldName, 'actionName' => 'findgridfield', - 'args' => null + 'args' => null ); // Ensure $id doesn't contain only numeric characters @@ -116,7 +147,7 @@ protected function getGridField() { // Simulate CSRF token use, hardcode to a random value in our fake session // so GridField can evaluate it in the Director::test() execution - $token = Injector::inst()->create('RandomGenerator')->randomToken('sha1'); + $token = Injector::inst()->create(RandomGenerator::class)->randomToken('sha1'); // Add new form action into session for GridField to find when Director::test is called below $session[$id] = $state; @@ -128,7 +159,7 @@ protected function getGridField() { $url = Controller::join_links( $this->GridFieldURL, - '?' .http_build_query([$actionKey => $actionValue, 'SecurityID' => $token]) + '?' . http_build_query([$actionKey => $actionValue, 'SecurityID' => $token]) ); // Restore into the current session the user the job is exporting as @@ -140,8 +171,8 @@ protected function getGridField() { // Great, it did, we can return it if ($res instanceof GridFieldQueuedExportButton_Response) { $gridField = $res->getGridField(); - $gridField->getConfig()->removeComponentsByType('GridFieldPaginator'); - $gridField->getConfig()->removeComponentsByType('GridFieldPageCount'); + $gridField->getConfig()->removeComponentsByType(GridFieldPaginator::class); + $gridField->getConfig()->removeComponentsByType(GridFieldPageCount::class); return $gridField; } else { @@ -153,7 +184,8 @@ protected function getGridField() { * @param $gridField * @param $columns */ - protected function outputHeader($gridField, $columns) { + protected function outputHeader($gridField, $columns) + { $fileData = ''; $separator = $this->Separator; @@ -179,7 +211,8 @@ protected function outputHeader($gridField, $columns) { * @param int $start * @param int $count */ - protected function outputRows(GridField $gridField, $columns, $start, $count) { + protected function outputRows(GridField $gridField, $columns, $start, $count) + { $fileData = ''; $separator = $this->Separator; @@ -223,7 +256,8 @@ protected function outputRows(GridField $gridField, $columns, $start, $count) { file_put_contents($this->getOutputPath(), $fileData, FILE_APPEND); } - public function setup() { + public function setup() + { $gridField = $this->getGridField(); $this->totalSteps = $gridField->getManipulatedList()->count(); } @@ -231,15 +265,15 @@ public function setup() { /** * Generate export fields for CSV. * - * @param GridField $gridField * @return array */ - public function process() { + public function process() + { $gridField = $this->getGridField(); - - if($this->Columns) { + + if ($this->Columns) { $columns = $this->Columns; - } else if($dataCols = $gridField->getConfig()->getComponentByType('GridFieldDataColumns')) { + } elseif ($dataCols = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class)) { $columns = $dataCols->getDisplayFields($gridField); } else { $columns = singleton($gridField->getModelClass())->summaryFields(); diff --git a/code/GridFieldQueuedExportButton.php b/src/GridFieldQueuedExportButton.php similarity index 66% rename from code/GridFieldQueuedExportButton.php rename to src/GridFieldQueuedExportButton.php index ea862e0..0e39c84 100644 --- a/code/GridFieldQueuedExportButton.php +++ b/src/GridFieldQueuedExportButton.php @@ -1,10 +1,28 @@ targetFragment = $targetFragment; $this->exportColumns = $exportColumns; } @@ -39,7 +58,8 @@ public function __construct($targetFragment = "after", $exportColumns = null) { /** * Place the export button in a

tag below the field */ - public function getHTMLFragments($gridField) { + public function getHTMLFragments($gridField) + { $button = new GridField_FormAction( $gridField, 'export', @@ -59,19 +79,22 @@ public function getHTMLFragments($gridField) { /** * This class is an action button */ - public function getActions($gridField) { + public function getActions($gridField) + { return array('export', 'findgridfield'); } - public function handleAction(GridField $gridField, $actionName, $arguments, $data) { + public function handleAction(GridField $gridField, $actionName, $arguments, $data) + { if ($actionName == 'export') { return $this->startExport($gridField); - } else if ($actionName == 'findgridfield') { + } elseif ($actionName == 'findgridfield') { return new GridFieldQueuedExportButton_Response($gridField); } } - function startExport($gridField) { + function startExport($gridField) + { $job = new GenerateCSVJob(); // Set the parameters that allow re-discovering this gridfield during background execution @@ -81,10 +104,12 @@ function startExport($gridField) { // Set the parameters that control CSV exporting $job->setSeparator($this->csvSeparator); $job->setIncludeHeader($this->csvHasHeader); - if ($this->exportColumns) $job->setColumns($this->exportColumns); + if ($this->exportColumns) { + $job->setColumns($this->exportColumns); + } // Queue the job - singleton('QueuedJobService')->queueJob($job); + singleton(QueuedJobService::class)->queueJob($job); // Redirect to the status update page return Controller::curr()->redirect($gridField->Link('/export/' . $job->getSignature())); @@ -93,26 +118,31 @@ function startExport($gridField) { /** * This class is also a URL handler */ - public function getURLHandlers($gridField) { + public function getURLHandlers($gridField) + { return array( - 'export/$ID' => 'checkExport', + 'export/$ID' => 'checkExport', 'export_download/$ID' => 'downloadExport' ); } - protected function getExportPath($id) { - if ($id instanceof QueuedJobDescriptor) $id = $id->Signature; - return ASSETS_PATH."/.exports/$id/$id.csv"; + protected function getExportPath($id) + { + if ($id instanceof QueuedJobDescriptor) { + $id = $id->Signature; + } + return ASSETS_PATH . "/.exports/$id/$id.csv"; } /** * Handle the export, for both the action button and the URL */ - public function checkExport($gridField, $request = null) { + public function checkExport($gridField, $request = null) + { $id = $request->param('ID'); $job = QueuedJobDescriptor::get()->filter('Signature', $id)->first(); - if ((int) $job->RunAsID !== Member::currentUserID()) { + if ((int)$job->RunAsID !== Security::getCurrentUser()) { return Security::permissionFailure(); } @@ -121,36 +151,36 @@ public function checkExport($gridField, $request = null) { $breadcrumbs = $controller->Breadcrumbs(false); $breadcrumbs->push(new ArrayData(array( 'Title' => _t('TableListField.CSVEXPORT', 'Export to CSV'), - 'Link' => false + 'Link' => false ))); $parents = $controller->Breadcrumbs(false)->items; $backlink = array_pop($parents)->Link; $data = new ArrayData(array( - 'ID' => $id, - 'Link' => Controller::join_links($gridField->Link(), 'export', $job->Signature), - 'Backlink' => $backlink, + 'ID' => $id, + 'Link' => Controller::join_links($gridField->Link(), 'export', $job->Signature), + 'Backlink' => $backlink, 'Breadcrumbs' => $breadcrumbs, - 'GridName' => $gridField->getname() + 'GridName' => $gridField->getname() )); if ($job->JobStatus == QueuedJob::STATUS_COMPLETE) { if (file_exists($this->getExportPath($id))) { $data->DownloadLink = $gridField->Link('/export_download/' . $job->Signature); - } - else { + } else { $data->ErrorMessage = _t( 'GridFieldQueuedExportButton.ERROR_REMOVED', - 'This export has already been downloaded. For security reasons each export can only be downloaded once.' + 'This export has already been downloaded. ' . + 'For security reasons each export can only be downloaded once.' ); } - } else if ($job->JobStatus == QueuedJob::STATUS_BROKEN) { + } elseif ($job->JobStatus == QueuedJob::STATUS_BROKEN) { $data->ErrorMessage = _t( 'GridFieldQueuedExportButton.ERROR_GENERAL', 'Sorry, but there was an error exporting the CSV' ); - } else if ($job->JobStatus == QueuedJob::STATUS_CANCELLED) { + } elseif ($job->JobStatus == QueuedJob::STATUS_CANCELLED) { $data->ErrorMessage = _t( 'GridFieldQueuedExportButton.CANCELLED', 'This export job was cancelled' @@ -163,7 +193,7 @@ public function checkExport($gridField, $request = null) { Requirements::javascript('gridfieldqueuedexport/client/GridFieldQueuedExportButton.js'); Requirements::css('gridfieldqueuedexport/client/GridFieldQueuedExportButton.css'); - $return = $data->renderWith('GridFieldQueuedExportButton'); + $return = $data->renderWith(GridFieldQueuedExportButton::class); if ($request->isAjax()) { return $return; @@ -172,11 +202,12 @@ public function checkExport($gridField, $request = null) { } } - public function downloadExport($gridField, $request = null) { + public function downloadExport($gridField, $request = null) + { $id = $request->param('ID'); $job = QueuedJobDescriptor::get()->filter('Signature', $id)->first(); - if ((int) $job->RunAsID !== Member::currentUserID()) { + if ((int)$job->RunAsID !== Security::getCurrentUser()) { return Security::permissionFailure(); } @@ -189,8 +220,8 @@ public function downloadExport($gridField, $request = null) { unlink($path); rmdir(dirname($path)); - $response = SS_HTTPRequest::send_file($content, $servedName, 'text/csv'); - $response->addHeader('Set-Cookie', 'downloaded_'.$id.'=true; Path=/'); + $response = HTTPRequest::send_file($content, $servedName, 'text/csv'); + $response->addHeader('Set-Cookie', 'downloaded_' . $id . '=true; Path=/'); return $response; } @@ -198,14 +229,17 @@ public function downloadExport($gridField, $request = null) { /** * @return array */ - public function getExportColumns() { + public function getExportColumns() + { return $this->exportColumns; } /** * @param array + * @return $this */ - public function setExportColumns($cols) { + public function setExportColumns($cols) + { $this->exportColumns = $cols; return $this; } @@ -213,14 +247,17 @@ public function setExportColumns($cols) { /** * @return string */ - public function getCsvSeparator() { + public function getCsvSeparator() + { return $this->csvSeparator; } /** * @param string + * @return $this */ - public function setCsvSeparator($separator) { + public function setCsvSeparator($separator) + { $this->csvSeparator = $separator; return $this; } @@ -228,32 +265,20 @@ public function setCsvSeparator($separator) { /** * @return boolean */ - public function getCsvHasHeader() { + public function getCsvHasHeader() + { return $this->csvHasHeader; } /** * @param boolean + * @return $this */ - public function setCsvHasHeader($bool) { + public function setCsvHasHeader($bool) + { $this->csvHasHeader = $bool; return $this; } } -/** - * A special type of SS_HTTPResponse that GridFieldQueuedExportButton returns in response to the "findgridfield" - * action, which includes a reference to the gridfield - */ -class GridFieldQueuedExportButton_Response extends SS_HTTPResponse { - private $gridField; - - public function __construct(GridField $gridField) { - $this->gridField = $gridField; - parent::__construct('', 500); - } - public function getGridField() { - return $this->gridField; - } -} diff --git a/src/GridFieldQueuedExportButton_Response.php b/src/GridFieldQueuedExportButton_Response.php new file mode 100644 index 0000000..477287e --- /dev/null +++ b/src/GridFieldQueuedExportButton_Response.php @@ -0,0 +1,26 @@ +gridField = $gridField; + parent::__construct('', 500); + } + + public function getGridField() + { + return $this->gridField; + } +} diff --git a/code/templates/GridFieldQueuedExportButton.ss b/templates/GridFieldQueuedExportButton.ss similarity index 100% rename from code/templates/GridFieldQueuedExportButton.ss rename to templates/GridFieldQueuedExportButton.ss diff --git a/tests/GenerateCSVJobTest.php b/tests/GenerateCSVJobTest.php index 1cd5801..3fe84e5 100644 --- a/tests/GenerateCSVJobTest.php +++ b/tests/GenerateCSVJobTest.php @@ -1,28 +1,40 @@ update('Director', 'rules', array( - 'jobtest//$Action/$ID/$OtherID' => 'GenerateCSVJobTest_Controller' + Config::inst()->update(Director::class, 'rules', array( + 'jobtest//$Action/$ID/$OtherID' => GenerateCSVJobTest_Controller::class )); } protected $paths = array(); - public function tearDown() { - foreach($this->paths as $path) { + public function tearDown() + { + foreach ($this->paths as $path) { Filesystem::removeFolder(dirname($path)); } parent::tearDown(); } - public function testGenerateExport() { + public function testGenerateExport() + { // Build session $memberID = $this->logInWithPermission('ADMIN'); $session = array('loggedInAs' => $memberID); @@ -61,7 +73,8 @@ public function testGenerateExport() { * @param array $session * @return GenerateCSVJob */ - protected function createJob($gridField, $session) { + protected function createJob($gridField, $session) + { $job = new GenerateCSVJob(); $job->setGridField($gridField); $job->setSession($session); @@ -71,42 +84,3 @@ protected function createJob($gridField, $session) { } } - -class GenerateCSVJobTest_Record extends DataObject implements TestOnly { - - private static $summary_fields = array( - 'Title', - 'Content', - 'PublishOn', - ); - - private static $default_sort = array( - 'Title', - ); - - private static $db = array( - 'Title' => 'Varchar', - 'Content' => 'Varchar', - 'PublishOn' => 'SS_DateTime' - ); -} - -class GenerateCSVJobTest_Controller extends Controller implements TestOnly { - private static $allowed_actions = array('Form'); - - public function Link() { - return 'jobtest/'; - } - - public function Form() { - // Get records - $records = GenerateCSVJobTest_Record::get(); - - // Set config - $config = GridFieldConfig_RecordEditor::create(); - $config->removeComponentsByType('GridFieldExportButton'); - $config->addComponent(new GridFieldQueuedExportButton('buttons-after-left')); - $fields = new GridField('MyGridfield', 'My Records', $records, $config); - return new Form($this, 'Form', new FieldList($fields), new FieldList()); - } -} diff --git a/tests/GenerateCSVJobTest_Controller.php b/tests/GenerateCSVJobTest_Controller.php new file mode 100644 index 0000000..bae6816 --- /dev/null +++ b/tests/GenerateCSVJobTest_Controller.php @@ -0,0 +1,40 @@ +removeComponentsByType(GridFieldExportButton::class); + $config->addComponent(new GridFieldQueuedExportButton('buttons-after-left')); + $fields = new GridField('MyGridfield', 'My Records', $records, $config); + return new Form($this, Form::class, new FieldList($fields), new FieldList()); + } +} diff --git a/tests/GenerateCSVJobTest_Record.php b/tests/GenerateCSVJobTest_Record.php new file mode 100644 index 0000000..2cfba41 --- /dev/null +++ b/tests/GenerateCSVJobTest_Record.php @@ -0,0 +1,28 @@ + 'Varchar', + 'Content' => 'Varchar', + 'PublishOn' => 'SS_DateTime' + ); +} From 85b2ce88dc53ce379d6c6c1f50168e2bbe2c80c0 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Mon, 15 Jan 2018 12:24:53 +1300 Subject: [PATCH 02/14] NEW Run upgrade translations tool --- lang/en.yml | 2 +- src/GridFieldQueuedExportButton.php | 12 +++++------- templates/GridFieldQueuedExportButton.ss | 10 +++++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lang/en.yml b/lang/en.yml index 7662762..c10e4bd 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -1,5 +1,5 @@ en: - GridFieldQueuedExportButton: + SilverStripe\GridfieldQueuedExport\GridFieldQueuedExportButton: AVAILABLE: 'Your export is available.' CANCELLED: 'This export job was cancelled' DOWNLOAD_CSV: 'Click here to download file as CSV.' diff --git a/src/GridFieldQueuedExportButton.php b/src/GridFieldQueuedExportButton.php index 0e39c84..f254dce 100644 --- a/src/GridFieldQueuedExportButton.php +++ b/src/GridFieldQueuedExportButton.php @@ -63,7 +63,7 @@ public function getHTMLFragments($gridField) $button = new GridField_FormAction( $gridField, 'export', - _t('TableListField.CSVEXPORT', 'Export to CSV'), + _t('SilverStripe\\Forms\\GridField\\GridField.CSVEXPORT', 'Export to CSV'), 'export', null ); @@ -150,7 +150,7 @@ public function checkExport($gridField, $request = null) $breadcrumbs = $controller->Breadcrumbs(false); $breadcrumbs->push(new ArrayData(array( - 'Title' => _t('TableListField.CSVEXPORT', 'Export to CSV'), + 'Title' => _t('SilverStripe\\Forms\\GridField\\GridField.CSVEXPORT', 'Export to CSV'), 'Link' => false ))); @@ -170,19 +170,19 @@ public function checkExport($gridField, $request = null) $data->DownloadLink = $gridField->Link('/export_download/' . $job->Signature); } else { $data->ErrorMessage = _t( - 'GridFieldQueuedExportButton.ERROR_REMOVED', + 'SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.ERROR_REMOVED', 'This export has already been downloaded. ' . 'For security reasons each export can only be downloaded once.' ); } } elseif ($job->JobStatus == QueuedJob::STATUS_BROKEN) { $data->ErrorMessage = _t( - 'GridFieldQueuedExportButton.ERROR_GENERAL', + 'SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.ERROR_GENERAL', 'Sorry, but there was an error exporting the CSV' ); } elseif ($job->JobStatus == QueuedJob::STATUS_CANCELLED) { $data->ErrorMessage = _t( - 'GridFieldQueuedExportButton.CANCELLED', + 'SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.CANCELLED', 'This export job was cancelled' ); } else { @@ -280,5 +280,3 @@ public function setCsvHasHeader($bool) return $this; } } - - diff --git a/templates/GridFieldQueuedExportButton.ss b/templates/GridFieldQueuedExportButton.ss index 0e6ef6b..2a96e2d 100644 --- a/templates/GridFieldQueuedExportButton.ss +++ b/templates/GridFieldQueuedExportButton.ss @@ -10,8 +10,8 @@

<% if $DownloadLink %>

- <%t GridFieldQueuedExportButton.AVAILABLE 'Your export is available.' %> - <%t GridFieldQueuedExportButton.DOWNLOAD_CSV 'Click here to download file as CSV.' %> + <%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.AVAILABLE 'Your export is available.' %> + <%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.DOWNLOAD_CSV 'Click here to download file as CSV.' %>

<% else_if $ErrorMessage %>

@@ -19,11 +19,11 @@

<% else %>

- <%t GridFieldQueuedExportButton.PREPARING_EXPORT 'Preparing export. This page will automatically refresh when export is available. You can bookmark this page and come back later if you like.' %> + <%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.PREPARING_EXPORT 'Preparing export. This page will automatically refresh when export is available. You can bookmark this page and come back later if you like.' %>

-

<%t GridFieldQueuedExportButton.EXPORTED_COUNT '{count} out of {total} records exported' count=$Count total=$Total %>

+

<%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.EXPORTED_COUNT '{count} out of {total} records exported' count=$Count total=$Total %>

<% end_if %> -

<%t GridFieldQueuedExportButton.RETURN 'Return to {name}' name=$GridName %>

+

<%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.RETURN 'Return to {name}' name=$GridName %>

From 7c6f33b40d019a0cca1d90ecbc20007583bd2bd7 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Mon, 15 Jan 2018 12:39:34 +1300 Subject: [PATCH 03/14] DOCS Update badges, requirements, and installation in README file --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b5f9432..a1391b2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # GridField Queued Export [![Build Status](https://travis-ci.org/silverstripe/silverstripe-gridfieldqueuedexport.svg?branch=master)](https://travis-ci.org/silverstripe/silverstripe-gridfieldqueuedexport) -![helpfulrobot](https://helpfulrobot.io/silverstripe/gridfieldqueuedexport/badge) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/silverstripe/silverstripe-gridfieldqueuedexport/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/silverstripe/silverstripe-gridfieldqueuedexport/?branch=master) +[![Code Coverage](https://codecov.io/gh/silverstripe/silverstripe-gridfieldqueuedexport/branch/master/graph/badge.svg)](https://codecov.io/gh/silverstripe/silverstripe-gridfielqueuedexport) ## Introduction @@ -16,13 +17,14 @@ when more than 1000 records need to be exported. The module should be able to ex ## Requirements - * SilverStripe 3.3+ + * SilverStripe 4.0+ * The [queuedjobs](https://github.com/silverstripe-australia/silverstripe-queuedjobs) module + + **Note:** For SilverStripe 3.x, please use the [1.x release line](https://github.com/silverstripe/silverstripe-gridfieldqueuedexport/tree/1.0). ## Installation via Composer - cd path/to/my/silverstripe/site - composer require "silverstripe/gridfieldqueuedexport:*" +To install run `composer require silverstripe/gridfieldqueuedexport`. ## Configuration From cb12b908ed5a7cfc1eef39a451b78844b95f182c Mon Sep 17 00:00:00 2001 From: Raissa North Date: Mon, 15 Jan 2018 14:10:34 +1300 Subject: [PATCH 04/14] API Add Forms and Jobs directory. Remove underscores from file and class names. Update namespaces. Clarify function visibility. --- .upgrade.yml | 8 ++++++++ .../UserFormUseQueuedExportExtension.php | 2 +- src/{ => Forms}/GridFieldQueuedExportButton.php | 8 ++++---- .../GridFieldQueuedExportButtonResponse.php} | 4 ++-- src/{ => Jobs}/GenerateCSVJob.php | 16 +++++++++------- tests/GenerateCSVJobTest.php | 10 +++++----- ...ller.php => GenerateCSVJobTestController.php} | 12 ++++-------- ...t_Record.php => GenerateCSVJobTestRecord.php} | 9 +++------ 8 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 .upgrade.yml rename src/{ => Forms}/GridFieldQueuedExportButton.php (97%) rename src/{GridFieldQueuedExportButton_Response.php => Forms/GridFieldQueuedExportButtonResponse.php} (81%) rename src/{ => Jobs}/GenerateCSVJob.php (95%) rename tests/{GenerateCSVJobTest_Controller.php => GenerateCSVJobTestController.php} (78%) rename tests/{GenerateCSVJobTest_Record.php => GenerateCSVJobTestRecord.php} (69%) diff --git a/.upgrade.yml b/.upgrade.yml new file mode 100644 index 0000000..aefba0a --- /dev/null +++ b/.upgrade.yml @@ -0,0 +1,8 @@ +mappings: + UserFormUseQueuedExportExtension: SilverStripe\GridfieldQueuedExport\Extensions\UserFormUseQueuedExportExtension + GenerateCSVJob: SilverStripe\GridfieldQueuedExport\Jobs\GenerateCSVJob + GridFieldQueuedExportButton: SilverStripe\GridfieldQueuedExport\Forms\GridFieldQueuedExportButton + GridFieldQueuedExportButton_Response: SilverStripe\GridfieldQueuedExport\Forms\GridFieldQueuedExportButtonResponse + GenerateCSVJobTest: SilverStripe\GridFieldQueuedExport\Tests\GenerateCSVJobTest + GenerateCSVJobTest_Record: SilverStripe\GridFieldQueuedExport\Tests\GenerateCSVJobTestRecord + GenerateCSVJobTest_Controller: SilverStripe\GridFieldQueuedExport\Tests\GenerateCSVJobTestController diff --git a/src/Extensions/UserFormUseQueuedExportExtension.php b/src/Extensions/UserFormUseQueuedExportExtension.php index f9d3746..22246ac 100644 --- a/src/Extensions/UserFormUseQueuedExportExtension.php +++ b/src/Extensions/UserFormUseQueuedExportExtension.php @@ -12,7 +12,7 @@ */ class UserFormUseQueuedExportExtension extends DataExtension { - function updateCMSFields(FieldList $fields) + public function updateCMSFields(FieldList $fields) { $gridField = $fields->fieldByName('Root.Submissions.Submissions'); diff --git a/src/GridFieldQueuedExportButton.php b/src/Forms/GridFieldQueuedExportButton.php similarity index 97% rename from src/GridFieldQueuedExportButton.php rename to src/Forms/GridFieldQueuedExportButton.php index f254dce..18aa665 100644 --- a/src/GridFieldQueuedExportButton.php +++ b/src/Forms/GridFieldQueuedExportButton.php @@ -1,6 +1,6 @@ startExport($gridField); } elseif ($actionName == 'findgridfield') { - return new GridFieldQueuedExportButton_Response($gridField); + return new GridFieldQueuedExportButtonResponse($gridField); } } - function startExport($gridField) + public function startExport($gridField) { $job = new GenerateCSVJob(); diff --git a/src/GridFieldQueuedExportButton_Response.php b/src/Forms/GridFieldQueuedExportButtonResponse.php similarity index 81% rename from src/GridFieldQueuedExportButton_Response.php rename to src/Forms/GridFieldQueuedExportButtonResponse.php index 477287e..6249236 100644 --- a/src/GridFieldQueuedExportButton_Response.php +++ b/src/Forms/GridFieldQueuedExportButtonResponse.php @@ -1,6 +1,6 @@ GridFieldName = $gridField->getName(); $this->GridFieldURL = $gridField->Link(); @@ -75,7 +77,7 @@ function setGridField(GridField $gridField) /** * @param $session */ - function setSession($session) + public function setSession($session) { // None of the gridfield actions are needed, and they make the stored session bigger, so pull // them out. @@ -91,17 +93,17 @@ function setSession($session) $this->Session = $session; } - function setColumns($columns) + public function setColumns($columns) { $this->Columns = $columns; } - function setSeparator($seperator) + public function setSeparator($seperator) { $this->Separator = $seperator; } - function setIncludeHeader($includeHeader) + public function setIncludeHeader($includeHeader) { $this->IncludeHeader = $includeHeader; } @@ -169,7 +171,7 @@ protected function getGridField() $res = Director::test($url, null, new Session($session), 'GET'); // Great, it did, we can return it - if ($res instanceof GridFieldQueuedExportButton_Response) { + if ($res instanceof GridFieldQueuedExportButtonResponse) { $gridField = $res->getGridField(); $gridField->getConfig()->removeComponentsByType(GridFieldPaginator::class); $gridField->getConfig()->removeComponentsByType(GridFieldPageCount::class); diff --git a/tests/GenerateCSVJobTest.php b/tests/GenerateCSVJobTest.php index 3fe84e5..092ba89 100644 --- a/tests/GenerateCSVJobTest.php +++ b/tests/GenerateCSVJobTest.php @@ -1,25 +1,26 @@ update(Director::class, 'rules', array( - 'jobtest//$Action/$ID/$OtherID' => GenerateCSVJobTest_Controller::class + 'jobtest//$Action/$ID/$OtherID' => GenerateCSVJobTestController::class )); } @@ -40,7 +41,7 @@ public function testGenerateExport() $session = array('loggedInAs' => $memberID); // Build controller - $controller = new GenerateCSVJobTest_Controller(); + $controller = new GenerateCSVJobTestController(); $form = $controller->Form(); $gridfield = $form->Fields()->fieldByName('MyGridfield'); @@ -83,4 +84,3 @@ protected function createJob($gridField, $session) return $job; } } - diff --git a/tests/GenerateCSVJobTest_Controller.php b/tests/GenerateCSVJobTestController.php similarity index 78% rename from tests/GenerateCSVJobTest_Controller.php rename to tests/GenerateCSVJobTestController.php index bae6816..73d1d38 100644 --- a/tests/GenerateCSVJobTest_Controller.php +++ b/tests/GenerateCSVJobTestController.php @@ -1,7 +1,6 @@ Date: Tue, 16 Jan 2018 12:00:58 +1300 Subject: [PATCH 05/14] API Vendorise module, update dependencies, add codesniff ruleset, style button, add doc blocks, update array syntax, update travis file --- .gitattributes | 1 + .travis.yml | 39 ++++++++----- LICENSE | 2 +- composer.json | 6 +- phpcs.xml.dist | 10 ++++ .../UserFormUseQueuedExportExtension.php | 2 +- src/Forms/GridFieldQueuedExportButton.php | 56 ++++++++++++++----- .../GridFieldQueuedExportButtonResponse.php | 5 +- src/Jobs/GenerateCSVJob.php | 39 +++++++++---- .../Forms}/GridFieldQueuedExportButton.ss | 6 +- tests/GenerateCSVJobTest.php | 17 +++--- tests/GenerateCSVJobTest.yml | 2 +- tests/GenerateCSVJobTestController.php | 14 +++-- tests/GenerateCSVJobTestRecord.php | 16 +++--- 14 files changed, 147 insertions(+), 68 deletions(-) create mode 100644 phpcs.xml.dist rename templates/{ => SilverStripe/GridFieldQueuedExport/Forms}/GridFieldQueuedExportButton.ss (91%) diff --git a/.gitattributes b/.gitattributes index 475f5f2..89eb187 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,3 +4,4 @@ /.gitignore export-ignore /.travis.yml export-ignore /.scrutinizer.yml export-ignore +/codecov.yml export-ignore diff --git a/.travis.yml b/.travis.yml index 4c27652..93f4e6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,33 @@ -# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details - -sudo: false - language: php +env: + global: + - COMPOSER_ROOT_VERSION="2.0.x-dev" + matrix: include: - - php: 5.4 - env: DB=SQLITE3 CORE_RELEASE=3 - - php: 5.5 - env: DB=PGSQL CORE_RELEASE=3 - php: 5.6 - env: DB=MYSQL CORE_RELEASE=3 + env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1 + - php: 7.0 + env: DB=PGSQL PHPUNIT_TEST=1 + - php: 7.1 + env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1 + - php: 7.2 + env: DB=MYSQL PHPUNIT_TEST=1 SUBSITES=1 before_script: - - composer self-update || true - - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support - - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss - - cd ~/builds/ss - - composer install + - phpenv rehash + - phpenv config-rm xdebug.ini + + - composer validate + - if [[ $DB == "PGSQL" ]]; then composer require --no-update silverstripe/postgresql 2.0.x-dev; fi + - if [[ $DB == "SUBSITES" ]]; then composer require --no-update silverstripe/subsites 2.0.x-dev; fi + - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile script: - - vendor/bin/phpunit gridfieldqueuedexport/tests + - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi + - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi + - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=vendor/silverstripe/framework/phpcs.xml.dist src tests; fi + +after_success: + - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi diff --git a/LICENSE b/LICENSE index 7c7a5b0..20c2e0c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 SilverStripe Ltd. +Copyright (c) 2018 SilverStripe Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 1ddf71d..fc7f477 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,13 @@ { "name": "silverstripe/gridfieldqueuedexport", "description": "Export large data sets from your GridField in the SilverStripe CMS interface through async jobs", - "type": "silverstripe-module", + "type": "silverstripe-vendormodule", "keywords": ["silverstripe", "queuedjobs", "export", "csv", "gridfield", "cwp"], "license": "BSD-3-Clause", "minimum-stability": "dev", "require": { - "silverstripe/framework": "^3.3", - "symbiote/silverstripe-queuedjobs": "^3" + "silverstripe/framework": "^4", + "symbiote/silverstripe-queuedjobs": "^4" }, "extra": { "branch-alias": { diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..f6e295b --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,10 @@ + + + CodeSniffer ruleset for SilverStripe coding conventions. + + + + + + + diff --git a/src/Extensions/UserFormUseQueuedExportExtension.php b/src/Extensions/UserFormUseQueuedExportExtension.php index 22246ac..4bc4f4d 100644 --- a/src/Extensions/UserFormUseQueuedExportExtension.php +++ b/src/Extensions/UserFormUseQueuedExportExtension.php @@ -4,7 +4,7 @@ use SilverStripe\Forms\FieldList; use SilverStripe\Forms\GridField\GridFieldExportButton; -use SilverStripe\GridfieldQueuedExport\GridFieldQueuedExportButton; +use SilverStripe\GridfieldQueuedExport\Forms\GridFieldQueuedExportButton; use SilverStripe\ORM\DataExtension; /** diff --git a/src/Forms/GridFieldQueuedExportButton.php b/src/Forms/GridFieldQueuedExportButton.php index 18aa665..082789b 100644 --- a/src/Forms/GridFieldQueuedExportButton.php +++ b/src/Forms/GridFieldQueuedExportButton.php @@ -4,6 +4,8 @@ use SilverStripe\Control\Controller; use SilverStripe\Control\HTTPRequest; +use SilverStripe\Control\HTTPResponse; +use SilverStripe\Core\Injector\Injector; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridField_ActionProvider; use SilverStripe\Forms\GridField\GridField_FormAction; @@ -60,7 +62,7 @@ public function __construct($targetFragment = "after", $exportColumns = null) */ public function getHTMLFragments($gridField) { - $button = new GridField_FormAction( + $button = GridField_FormAction::create( $gridField, 'export', _t('SilverStripe\\Forms\\GridField\\GridField.CSVEXPORT', 'Export to CSV'), @@ -68,22 +70,32 @@ public function getHTMLFragments($gridField) null ); $button->setAttribute('data-icon', 'download-csv'); - $button->addExtraClass('action_batch_export'); + $button->addExtraClass('btn btn-secondary no-ajax font-icon-down-circled action_export action_batch_export'); $button->setForm($gridField->getForm()); - return array( + return [ $this->targetFragment => '

' . $button->Field() . '

', - ); + ]; } + /** * This class is an action button + * + * @param $gridField + * @return array */ public function getActions($gridField) { return array('export', 'findgridfield'); } + /** + * @param GridField $gridField + * @param string $actionName + * @param array $arguments + * @param array $data + */ public function handleAction(GridField $gridField, $actionName, $arguments, $data) { if ($actionName == 'export') { @@ -93,13 +105,17 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat } } + /** + * @param $gridField + * @return HTTPResponse + */ public function startExport($gridField) { $job = new GenerateCSVJob(); // Set the parameters that allow re-discovering this gridfield during background execution $job->setGridField($gridField); - $job->setSession(Controller::curr()->getSession()->get_all()); + $job->setSession(Injector::inst()->get(HTTPRequest::class)->getSession()->getAll()); // Set the parameters that control CSV exporting $job->setSeparator($this->csvSeparator); @@ -115,15 +131,19 @@ public function startExport($gridField) return Controller::curr()->redirect($gridField->Link('/export/' . $job->getSignature())); } + /** * This class is also a URL handler + * + * @param GridField $gridField + * @return array */ public function getURLHandlers($gridField) { - return array( + return [ 'export/$ID' => 'checkExport', 'export_download/$ID' => 'downloadExport' - ); + ]; } protected function getExportPath($id) @@ -134,36 +154,41 @@ protected function getExportPath($id) return ASSETS_PATH . "/.exports/$id/$id.csv"; } + /** * Handle the export, for both the action button and the URL + * + * @param $gridField + * @param null $request + * @return \SilverStripe\Control\HTTPResponse|\SilverStripe\ORM\FieldType\DBHTMLText */ public function checkExport($gridField, $request = null) { $id = $request->param('ID'); $job = QueuedJobDescriptor::get()->filter('Signature', $id)->first(); - if ((int)$job->RunAsID !== Security::getCurrentUser()) { + if ((int)$job->RunAsID !== Security::getCurrentUser()->ID) { return Security::permissionFailure(); } $controller = $gridField->getForm()->getController(); $breadcrumbs = $controller->Breadcrumbs(false); - $breadcrumbs->push(new ArrayData(array( + $breadcrumbs->push(new ArrayData([ 'Title' => _t('SilverStripe\\Forms\\GridField\\GridField.CSVEXPORT', 'Export to CSV'), 'Link' => false - ))); + ])); $parents = $controller->Breadcrumbs(false)->items; $backlink = array_pop($parents)->Link; - $data = new ArrayData(array( + $data = new ArrayData([ 'ID' => $id, 'Link' => Controller::join_links($gridField->Link(), 'export', $job->Signature), 'Backlink' => $backlink, 'Breadcrumbs' => $breadcrumbs, 'GridName' => $gridField->getname() - )); + ]); if ($job->JobStatus == QueuedJob::STATUS_COMPLETE) { if (file_exists($this->getExportPath($id))) { @@ -198,10 +223,15 @@ public function checkExport($gridField, $request = null) if ($request->isAjax()) { return $return; } else { - return $controller->customise(array('Content' => $return)); + return $controller->customise(['Content' => $return]); } } + /** + * @param $gridField + * @param null $request + * @return HTTPResponse + */ public function downloadExport($gridField, $request = null) { $id = $request->param('ID'); diff --git a/src/Forms/GridFieldQueuedExportButtonResponse.php b/src/Forms/GridFieldQueuedExportButtonResponse.php index 6249236..c8f0eb6 100644 --- a/src/Forms/GridFieldQueuedExportButtonResponse.php +++ b/src/Forms/GridFieldQueuedExportButtonResponse.php @@ -11,7 +11,10 @@ */ class GridFieldQueuedExportButtonResponse extends HTTPResponse { - private $gridField; + /** + * @var GridField + */ + protected $gridField; public function __construct(GridField $gridField) { diff --git a/src/Jobs/GenerateCSVJob.php b/src/Jobs/GenerateCSVJob.php index 9cc7f75..937518e 100644 --- a/src/Jobs/GenerateCSVJob.php +++ b/src/Jobs/GenerateCSVJob.php @@ -4,6 +4,8 @@ use SilverStripe\Control\Controller; use SilverStripe\Control\Director; +use SilverStripe\Control\HTTPRequest; +use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\Session; use SilverStripe\Core\Injector\Injector; use SilverStripe\Forms\GridField\GridField; @@ -31,6 +33,10 @@ */ class GenerateCSVJob extends AbstractQueuedJob { + /** + * @var array + */ + protected $session; public function __construct() { @@ -75,7 +81,8 @@ public function setGridField(GridField $gridField) } /** - * @param $session + * @param array $session + * @return $this */ public function setSession($session) { @@ -90,7 +97,14 @@ public function setSession($session) // This causes problems with logins unset($session['HTTP_USER_AGENT']); - $this->Session = $session; + $this->session = $session; + + return $this; + } + + public function getSession() + { + return $this->session; } public function setColumns($columns) @@ -129,20 +143,22 @@ protected function getOutputPath() return $folder . '/' . $this->getSignature() . '.csv'; } + /** + * @throws HTTPResponse_Exception * @return GridField - * @throws SS_HTTPResponse_Exception */ protected function getGridField() { - $session = $this->Session; + /** @var array $session */ + $session = $this->getSession(); // Store state in session, and pass ID to client side. - $state = array( + $state = [ 'grid' => $this->GridFieldName, 'actionName' => 'findgridfield', 'args' => null - ); + ]; // Ensure $id doesn't contain only numeric characters $id = 'gf_' . substr(md5(serialize($state)), 0, 8); @@ -165,7 +181,7 @@ protected function getGridField() ); // Restore into the current session the user the job is exporting as - Session::set("loggedInAs", $session['loggedInAs']); + Injector::inst()->get(HTTPRequest::class)->getSession()->set("loggedInAs", $session['loggedInAs']); // Then make a sub-query that should return a special SS_HTTPResponse with the gridfield object $res = Director::test($url, null, new Session($session), 'GET'); @@ -191,7 +207,7 @@ protected function outputHeader($gridField, $columns) $fileData = ''; $separator = $this->Separator; - $headers = array(); + $headers = []; // determine the CSV headers. If a field is callable (e.g. anonymous function) then use the // source name as the header instead @@ -223,7 +239,7 @@ protected function outputRows(GridField $gridField, $columns, $start, $count) foreach ($items as $item) { if (!$item->hasMethod('canView') || $item->canView()) { - $columnData = array(); + $columnData = []; foreach ($columns as $columnSource => $columnHeader) { if (!is_string($columnHeader) && is_callable($columnHeader)) { @@ -242,7 +258,7 @@ protected function outputRows(GridField $gridField, $columns, $start, $count) } } - $value = str_replace(array("\r", "\n"), "\n", $value); + $value = str_replace(["\r", "\n"], "\n", $value); $columnData[] = '"' . str_replace('"', '""', $value) . '"'; } @@ -264,10 +280,9 @@ public function setup() $this->totalSteps = $gridField->getManipulatedList()->count(); } + /** * Generate export fields for CSV. - * - * @return array */ public function process() { diff --git a/templates/GridFieldQueuedExportButton.ss b/templates/SilverStripe/GridFieldQueuedExport/Forms/GridFieldQueuedExportButton.ss similarity index 91% rename from templates/GridFieldQueuedExportButton.ss rename to templates/SilverStripe/GridFieldQueuedExport/Forms/GridFieldQueuedExportButton.ss index 2a96e2d..f5644e9 100644 --- a/templates/GridFieldQueuedExportButton.ss +++ b/templates/SilverStripe/GridFieldQueuedExport/Forms/GridFieldQueuedExportButton.ss @@ -2,8 +2,8 @@
- <% include BackLink_Button %> - <% include CMSBreadcrumbs %> + <% include SilverStripe\\Admin\\BackLink_Button %> + <% include SilverStripe\\Admin\\CMSBreadcrumbs %>
@@ -25,5 +25,5 @@ <% end_if %>

<%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.RETURN 'Return to {name}' name=$GridName %>

- +

Hello world

diff --git a/tests/GenerateCSVJobTest.php b/tests/GenerateCSVJobTest.php index 092ba89..c9ffa16 100644 --- a/tests/GenerateCSVJobTest.php +++ b/tests/GenerateCSVJobTest.php @@ -14,19 +14,22 @@ class GenerateCSVJobTest extends SapphireTest protected static $fixture_file = 'GenerateCSVJobTest.yml'; - protected $extraDataObjects = array(GenerateCSVJobTestRecord::class); + protected static $extra_dataobjects = [GenerateCSVJobTestRecord::class]; - public function setUp() + protected static $extra_controllers = [GenerateCSVJobTestController::class]; + + protected function setUp() { parent::setUp(); - Config::inst()->update(Director::class, 'rules', array( + + Config::modify()->merge(Director::class, 'rules', [ 'jobtest//$Action/$ID/$OtherID' => GenerateCSVJobTestController::class - )); + ]); } - protected $paths = array(); + protected $paths = []; - public function tearDown() + protected function tearDown() { foreach ($this->paths as $path) { Filesystem::removeFolder(dirname($path)); @@ -38,7 +41,7 @@ public function testGenerateExport() { // Build session $memberID = $this->logInWithPermission('ADMIN'); - $session = array('loggedInAs' => $memberID); + $session = ['loggedInAs' => $memberID]; // Build controller $controller = new GenerateCSVJobTestController(); diff --git a/tests/GenerateCSVJobTest.yml b/tests/GenerateCSVJobTest.yml index 289191d..0bb0627 100644 --- a/tests/GenerateCSVJobTest.yml +++ b/tests/GenerateCSVJobTest.yml @@ -1,4 +1,4 @@ -GenerateCSVJobTest_Record: +SilverStripe\GridFieldQueuedExport\Tests\GenerateCSVJobTestRecord: record1: Title: 'Record 1' Content: '

"Record 1" Body

' diff --git a/tests/GenerateCSVJobTestController.php b/tests/GenerateCSVJobTestController.php index 73d1d38..9e10a89 100644 --- a/tests/GenerateCSVJobTestController.php +++ b/tests/GenerateCSVJobTestController.php @@ -9,18 +9,23 @@ use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor; use SilverStripe\Forms\GridField\GridFieldExportButton; - use SilverStripe\GridfieldQueuedExport\Forms\GridFieldQueuedExportButton; class GenerateCSVJobTestController extends Controller implements TestOnly { - private static $allowed_actions = array('Form'); + private static $allowed_actions = ['Form']; - public function Link() + /** + * @return string + */ + public function Link($action = null) { return 'jobtest/'; } + /** + * @return Form + */ public function Form() { // Get records @@ -31,6 +36,7 @@ public function Form() $config->removeComponentsByType(GridFieldExportButton::class); $config->addComponent(new GridFieldQueuedExportButton('buttons-after-left')); $fields = new GridField('MyGridfield', 'My Records', $records, $config); - return new Form($this, Form::class, new FieldList($fields), new FieldList()); + /** @skipUpgrade */ + return Form::create($this, 'Form', new FieldList($fields), new FieldList()); } } diff --git a/tests/GenerateCSVJobTestRecord.php b/tests/GenerateCSVJobTestRecord.php index f2546d3..7dbf6ee 100644 --- a/tests/GenerateCSVJobTestRecord.php +++ b/tests/GenerateCSVJobTestRecord.php @@ -7,19 +7,21 @@ class GenerateCSVJobTestRecord extends DataObject implements TestOnly { - private static $summary_fields = array( + private static $table_name = 'GenerateCSVJobTestRecord'; + + private static $summary_fields = [ 'Title', 'Content', 'PublishOn', - ); + ]; - private static $default_sort = array( + private static $default_sort = [ 'Title', - ); + ]; - private static $db = array( + private static $db = [ 'Title' => 'Varchar', 'Content' => 'Varchar', - 'PublishOn' => 'SS_DateTime' - ); + 'PublishOn' => 'Datetime' + ]; } From e6fbc94846b544b23e63437852c4fec421051fa2 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Tue, 16 Jan 2018 13:51:33 +1300 Subject: [PATCH 06/14] FIX Expose client in composer.json --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index fc7f477..56d61c3 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,9 @@ "symbiote/silverstripe-queuedjobs": "^4" }, "extra": { + "expose": [ + "client" + ], "branch-alias": { "dev-master": "2.x-dev" } From a344f328828e89cc33937b91ff2d312bc21ede79 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Tue, 16 Jan 2018 13:52:33 +1300 Subject: [PATCH 07/14] API Update request and session handling. Tests passing. --- src/Forms/GridFieldQueuedExportButton.php | 14 +++---- src/Jobs/GenerateCSVJob.php | 39 ++++++++++++------- .../Forms/GridFieldQueuedExportButton.ss | 14 +++---- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/Forms/GridFieldQueuedExportButton.php b/src/Forms/GridFieldQueuedExportButton.php index 082789b..df24312 100644 --- a/src/Forms/GridFieldQueuedExportButton.php +++ b/src/Forms/GridFieldQueuedExportButton.php @@ -215,8 +215,8 @@ public function checkExport($gridField, $request = null) $data->Total = $job->TotalSteps; } - Requirements::javascript('gridfieldqueuedexport/client/GridFieldQueuedExportButton.js'); - Requirements::css('gridfieldqueuedexport/client/GridFieldQueuedExportButton.css'); + Requirements::javascript('silverstripe/gridfieldqueuedexport:client/GridFieldQueuedExportButton.js'); + Requirements::css('silverstripe/gridfieldqueuedexport:client/GridFieldQueuedExportButton.css'); $return = $data->renderWith(GridFieldQueuedExportButton::class); @@ -228,8 +228,8 @@ public function checkExport($gridField, $request = null) } /** - * @param $gridField - * @param null $request + * @param GridField $gridField + * @param HTTPRequest $request * @return HTTPResponse */ public function downloadExport($gridField, $request = null) @@ -237,7 +237,7 @@ public function downloadExport($gridField, $request = null) $id = $request->param('ID'); $job = QueuedJobDescriptor::get()->filter('Signature', $id)->first(); - if ((int)$job->RunAsID !== Security::getCurrentUser()) { + if ((int)$job->RunAsID !== Security::getCurrentUser()->ID) { return Security::permissionFailure(); } @@ -252,8 +252,8 @@ public function downloadExport($gridField, $request = null) $response = HTTPRequest::send_file($content, $servedName, 'text/csv'); $response->addHeader('Set-Cookie', 'downloaded_' . $id . '=true; Path=/'); - - return $response; + $response->output(); + exit; } /** diff --git a/src/Jobs/GenerateCSVJob.php b/src/Jobs/GenerateCSVJob.php index 937518e..16fe038 100644 --- a/src/Jobs/GenerateCSVJob.php +++ b/src/Jobs/GenerateCSVJob.php @@ -33,11 +33,6 @@ */ class GenerateCSVJob extends AbstractQueuedJob { - /** - * @var array - */ - protected $session; - public function __construct() { $this->ID = Injector::inst()->create(RandomGenerator::class)->randomToken('sha1'); @@ -82,7 +77,6 @@ public function setGridField(GridField $gridField) /** * @param array $session - * @return $this */ public function setSession($session) { @@ -97,14 +91,7 @@ public function setSession($session) // This causes problems with logins unset($session['HTTP_USER_AGENT']); - $this->session = $session; - - return $this; - } - - public function getSession() - { - return $this->session; + $this->Session = $session; } public function setColumns($columns) @@ -150,8 +137,10 @@ protected function getOutputPath() */ protected function getGridField() { + $this->initRequest(); + /** @var array $session */ - $session = $this->getSession(); + $session = $this->Session; // Store state in session, and pass ID to client side. $state = [ @@ -280,6 +269,26 @@ public function setup() $this->totalSteps = $gridField->getManipulatedList()->count(); } + /** + * Normally Director::handleRequest will register an HTTPRequest service. If that hasn't happened yet, we will + * register one instead. Also register a new controller if one hasn't been pushed yet. + */ + protected function initRequest() + { + if (!Injector::inst()->has(HTTPRequest::class)) { + $request = new HTTPRequest('GET', '/'); + $request->setSession(new Session([])); + + Injector::inst()->registerService($request); + } + + if (!Controller::has_curr()) { + $controller = new Controller(); + $controller->setRequest(Injector::inst()->get(HTTPRequest::class)); + $controller->pushCurrent(); + } + } + /** * Generate export fields for CSV. diff --git a/templates/SilverStripe/GridFieldQueuedExport/Forms/GridFieldQueuedExportButton.ss b/templates/SilverStripe/GridFieldQueuedExport/Forms/GridFieldQueuedExportButton.ss index f5644e9..41b80f7 100644 --- a/templates/SilverStripe/GridFieldQueuedExport/Forms/GridFieldQueuedExportButton.ss +++ b/templates/SilverStripe/GridFieldQueuedExport/Forms/GridFieldQueuedExportButton.ss @@ -1,17 +1,17 @@ -
+
-
-
+
+
<% include SilverStripe\\Admin\\BackLink_Button %> <% include SilverStripe\\Admin\\CMSBreadcrumbs %>
-
+
<% if $DownloadLink %>

<%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.AVAILABLE 'Your export is available.' %> - <%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.DOWNLOAD_CSV 'Click here to download file as CSV.' %> + <%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.DOWNLOAD_CSV 'Click here to download file as CSV.' %>

<% else_if $ErrorMessage %>

@@ -23,7 +23,7 @@

<%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.EXPORTED_COUNT '{count} out of {total} records exported' count=$Count total=$Total %>

<% end_if %> -

<%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.RETURN 'Return to {name}' name=$GridName %>

+

<%t SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.RETURN 'Return to {name}' name=$GridName %>

-

Hello world

+
From 4e286b4a77900b2d5b9937832c343cbe90f112ea Mon Sep 17 00:00:00 2001 From: Raissa North Date: Tue, 16 Jan 2018 15:12:46 +1300 Subject: [PATCH 08/14] NEW Add javascript i18n translations, update namespace in YAML lang files --- .tx/config | 6 ++++++ client/lang/en.js | 11 +++++++++++ client/lang/src/en.json | 3 +++ lang/eo.yml | 2 +- lang/ru.yml | 2 +- src/Forms/GridFieldQueuedExportButton.php | 1 + 6 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 client/lang/en.js create mode 100644 client/lang/src/en.json diff --git a/.tx/config b/.tx/config index be415b5..c1aaac9 100644 --- a/.tx/config +++ b/.tx/config @@ -6,3 +6,9 @@ file_filter = lang/.yml source_file = lang/en.yml source_lang = en type = YML + +[silverstripe-gridfieldqueuedexport.master-js] +file_filter = client/lang/src/.json +source_file = client/lang/src/en.json +source_lang = en +type = KEYVALUEJSON diff --git a/client/lang/en.js b/client/lang/en.js new file mode 100644 index 0000000..9b0aebf --- /dev/null +++ b/client/lang/en.js @@ -0,0 +1,11 @@ +// This file was generated by silverstripe/cow from client/lang/src/en.json. +// See https://github.com/tractorcow/cow for details +if (typeof(ss) === 'undefined' || typeof(ss.i18n) === 'undefined') { + if (typeof(console) !== 'undefined') { // eslint-disable-line no-console + console.error('Class ss.i18n not defined'); // eslint-disable-line no-console + } +} else { + ss.i18n.addDictionary('en', { + "GridFieldQueuedExportButton.DOWNLOADED": "Your export has been downloaded." + }); +} diff --git a/client/lang/src/en.json b/client/lang/src/en.json new file mode 100644 index 0000000..eb06ac1 --- /dev/null +++ b/client/lang/src/en.json @@ -0,0 +1,3 @@ +{ + "GridFieldQueuedExportButton.DOWNLOADED": "Your export has been downloaded." +} diff --git a/lang/eo.yml b/lang/eo.yml index efb6f03..41cb70b 100644 --- a/lang/eo.yml +++ b/lang/eo.yml @@ -1,5 +1,5 @@ eo: - GridFieldQueuedExportButton: + SilverStripe\GridfieldQueuedExport\GridFieldQueuedExportButton: AVAILABLE: 'Via eksporto estas havebla' CANCELLED: 'Ĉi tiu eksporta tasko estas nuligita' DOWNLOAD_CSV: 'Alklaku ĉi tie por elŝuti dosieron kiel CSV.' diff --git a/lang/ru.yml b/lang/ru.yml index f785b1e..f417b5a 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -1,5 +1,5 @@ ru: - GridFieldQueuedExportButton: + SilverStripe\GridfieldQueuedExport\GridFieldQueuedExportButton: AVAILABLE: 'Экспортированные данные готовы.' CANCELLED: 'Задача экспорта отменена' DOWNLOAD_CSV: 'Нажмите для скачивания CSV-файла.' diff --git a/src/Forms/GridFieldQueuedExportButton.php b/src/Forms/GridFieldQueuedExportButton.php index df24312..ca9b9ae 100644 --- a/src/Forms/GridFieldQueuedExportButton.php +++ b/src/Forms/GridFieldQueuedExportButton.php @@ -215,6 +215,7 @@ public function checkExport($gridField, $request = null) $data->Total = $job->TotalSteps; } + Requirements::add_i18n_javascript('silverstripe/gridfieldqueuedexport:client/lang'); Requirements::javascript('silverstripe/gridfieldqueuedexport:client/GridFieldQueuedExportButton.js'); Requirements::css('silverstripe/gridfieldqueuedexport:client/GridFieldQueuedExportButton.css'); From 2ec3cbd525619662c0b5086b515a6bdddc13095c Mon Sep 17 00:00:00 2001 From: Raissa North Date: Tue, 16 Jan 2018 15:36:00 +1300 Subject: [PATCH 09/14] FIX Update types in doc blocks --- src/Forms/GridFieldQueuedExportButton.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Forms/GridFieldQueuedExportButton.php b/src/Forms/GridFieldQueuedExportButton.php index ca9b9ae..312e46e 100644 --- a/src/Forms/GridFieldQueuedExportButton.php +++ b/src/Forms/GridFieldQueuedExportButton.php @@ -11,6 +11,7 @@ use SilverStripe\Forms\GridField\GridField_FormAction; use SilverStripe\Forms\GridField\GridField_HTMLProvider; use SilverStripe\Forms\GridField\GridField_URLHandler; +use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\Security\Security; use SilverStripe\View\ArrayData; use SilverStripe\View\Requirements; @@ -82,12 +83,12 @@ public function getHTMLFragments($gridField) /** * This class is an action button * - * @param $gridField + * @param GridField $gridField * @return array */ public function getActions($gridField) { - return array('export', 'findgridfield'); + return ['export', 'findgridfield']; } /** @@ -106,7 +107,7 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat } /** - * @param $gridField + * @param GridField $gridField * @return HTTPResponse */ public function startExport($gridField) @@ -158,9 +159,9 @@ protected function getExportPath($id) /** * Handle the export, for both the action button and the URL * - * @param $gridField - * @param null $request - * @return \SilverStripe\Control\HTTPResponse|\SilverStripe\ORM\FieldType\DBHTMLText + * @param GridField $gridField + * @param HTTPRequest $request + * @return HTTPResponse|DBHTMLText */ public function checkExport($gridField, $request = null) { From dcdab222e2450f012310428502fcb757b4bd466d Mon Sep 17 00:00:00 2001 From: Raissa North Date: Wed, 17 Jan 2018 11:19:19 +1300 Subject: [PATCH 10/14] FIX Update editorconfig to apply to composer.json, update spacing in composer.json, make comment for initRequest() clearer --- .editorconfig | 9 +++++- README.md | 2 +- composer.json | 39 +++++++++++++++-------- src/Forms/GridFieldQueuedExportButton.php | 2 +- src/Jobs/GenerateCSVJob.php | 5 +-- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/.editorconfig b/.editorconfig index 47ae637..3ef7d71 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,8 +10,15 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true -[{*.yml,package.json}] +[*.md] +trim_trailing_whitespace = false + +[*.{yml,js,json,css,scss,feature}] indent_size = 2 +indent_style = space + +[composer.json] +indent_size = 4 # The indent size used in the package.json file cannot be changed: # https://github.com/npm/npm/pull/3180#issuecomment-16336516 diff --git a/README.md b/README.md index a1391b2..f0e7396 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ when more than 1000 records need to be exported. The module should be able to ex **Note:** For SilverStripe 3.x, please use the [1.x release line](https://github.com/silverstripe/silverstripe-gridfieldqueuedexport/tree/1.0). -## Installation via Composer +## Installation To install run `composer require silverstripe/gridfieldqueuedexport`. diff --git a/composer.json b/composer.json index 56d61c3..b44bae0 100644 --- a/composer.json +++ b/composer.json @@ -1,21 +1,32 @@ { - "name": "silverstripe/gridfieldqueuedexport", - "description": "Export large data sets from your GridField in the SilverStripe CMS interface through async jobs", - "type": "silverstripe-vendormodule", - "keywords": ["silverstripe", "queuedjobs", "export", "csv", "gridfield", "cwp"], - "license": "BSD-3-Clause", - "minimum-stability": "dev", - "require": { - "silverstripe/framework": "^4", + "name": "silverstripe/gridfieldqueuedexport", + "description": "Export large data sets from your GridField in the SilverStripe CMS interface through async jobs", + "type": "silverstripe-vendormodule", + "keywords": [ + "silverstripe", + "queuedjobs", + "export", + "csv", + "gridfield", + "cwp" + ], + "license": "BSD-3-Clause", + "minimum-stability": "dev", + "require": { + "silverstripe/framework": "^4", "symbiote/silverstripe-queuedjobs": "^4" - }, - "extra": { + }, + "require-dev": { + "phpunit/phpunit": "^5.7", + "squizlabs/php_codesniffer": "^3.0" + }, + "extra": { "expose": [ "client" ], - "branch-alias": { - "dev-master": "2.x-dev" - } - } + "branch-alias": { + "dev-master": "2.x-dev" + } + } } diff --git a/src/Forms/GridFieldQueuedExportButton.php b/src/Forms/GridFieldQueuedExportButton.php index 312e46e..d26148c 100644 --- a/src/Forms/GridFieldQueuedExportButton.php +++ b/src/Forms/GridFieldQueuedExportButton.php @@ -203,7 +203,7 @@ public function checkExport($gridField, $request = null) } } elseif ($job->JobStatus == QueuedJob::STATUS_BROKEN) { $data->ErrorMessage = _t( - 'SilverStripe\\GridfieldQueuedExport\\GridFieldQueuedExportButton.ERROR_GENERAL', + __CLASS__.'.ERROR_GENERAL', 'Sorry, but there was an error exporting the CSV' ); } elseif ($job->JobStatus == QueuedJob::STATUS_CANCELLED) { diff --git a/src/Jobs/GenerateCSVJob.php b/src/Jobs/GenerateCSVJob.php index 16fe038..00374c4 100644 --- a/src/Jobs/GenerateCSVJob.php +++ b/src/Jobs/GenerateCSVJob.php @@ -270,8 +270,9 @@ public function setup() } /** - * Normally Director::handleRequest will register an HTTPRequest service. If that hasn't happened yet, we will - * register one instead. Also register a new controller if one hasn't been pushed yet. + * Normally Director::handleRequest will register an HTTPRequest service (when routing via frontend controllers). + * If that hasn't happened yet, we will register one instead (e.g. for unit testing, or when running from the command + * line). Also register a new controller if one hasn't been pushed yet. */ protected function initRequest() { From 7ec5910f6fc1e40e9168ebe874aae5c5be174031 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Wed, 17 Jan 2018 13:24:14 +1300 Subject: [PATCH 11/14] FIX Add prefer-stable true directive to composer.json --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b44bae0..a9e4c3d 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "branch-alias": { "dev-master": "2.x-dev" } - } + }, + "prefer-stable": true } From d2e07935981d565187409738f3cca4aad721045b Mon Sep 17 00:00:00 2001 From: Raissa North Date: Thu, 18 Jan 2018 09:38:38 +1300 Subject: [PATCH 12/14] FIX Update travis.yml to use module's code sniffer rule set --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 93f4e6c..1ce0f6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ before_script: script: - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi - - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=vendor/silverstripe/framework/phpcs.xml.dist src tests; fi + - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src tests; fi after_success: - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi From ddc5fdee6d6e73c1e6136be80cfb4c1709b2cf88 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Thu, 18 Jan 2018 09:49:41 +1300 Subject: [PATCH 13/14] Add phpunit configuration bootstrap file, delete changelog file --- .travis.yml | 2 +- changelog.md | 9 --------- phpunit.xml.dist | 14 ++++++++++++++ 3 files changed, 15 insertions(+), 10 deletions(-) delete mode 100644 changelog.md create mode 100644 phpunit.xml.dist diff --git a/.travis.yml b/.travis.yml index 1ce0f6e..a0f1190 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ before_script: - composer validate - if [[ $DB == "PGSQL" ]]; then composer require --no-update silverstripe/postgresql 2.0.x-dev; fi - - if [[ $DB == "SUBSITES" ]]; then composer require --no-update silverstripe/subsites 2.0.x-dev; fi + - if [[ $SUBSITES ]]; then composer require --no-update silverstripe/subsites 2.0.x-dev; fi - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile script: diff --git a/changelog.md b/changelog.md deleted file mode 100644 index 6fa94ba..0000000 --- a/changelog.md +++ /dev/null @@ -1,9 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -This project adheres to [Semantic Versioning](http://semver.org/). - -## [1.0.0-rc1] - - * Initial release candidate diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..8700f65 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,14 @@ + + + tests/ + + + + + src/ + + tests/ + + + + From fbd89b31a20b44aaedd6d849a9241e6ec49b92a1 Mon Sep 17 00:00:00 2001 From: Raissa North Date: Thu, 18 Jan 2018 10:40:35 +1300 Subject: [PATCH 14/14] FIX Remove subsites from the module and fix linting error --- .travis.yml | 3 +-- src/Jobs/GenerateCSVJob.php | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index a0f1190..bbbf9a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ matrix: - php: 7.1 env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1 - php: 7.2 - env: DB=MYSQL PHPUNIT_TEST=1 SUBSITES=1 + env: DB=MYSQL PHPUNIT_TEST=1 before_script: - phpenv rehash @@ -21,7 +21,6 @@ before_script: - composer validate - if [[ $DB == "PGSQL" ]]; then composer require --no-update silverstripe/postgresql 2.0.x-dev; fi - - if [[ $SUBSITES ]]; then composer require --no-update silverstripe/subsites 2.0.x-dev; fi - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile script: diff --git a/src/Jobs/GenerateCSVJob.php b/src/Jobs/GenerateCSVJob.php index 00374c4..29b049e 100644 --- a/src/Jobs/GenerateCSVJob.php +++ b/src/Jobs/GenerateCSVJob.php @@ -271,8 +271,8 @@ public function setup() /** * Normally Director::handleRequest will register an HTTPRequest service (when routing via frontend controllers). - * If that hasn't happened yet, we will register one instead (e.g. for unit testing, or when running from the command - * line). Also register a new controller if one hasn't been pushed yet. + * If that hasn't happened yet, we will register one instead (e.g. for unit testing, or when running from the + * command line). Also register a new controller if one hasn't been pushed yet. */ protected function initRequest() {