Skip to content

Commit

Permalink
API Add Forms and Jobs directory. Remove underscores from file and cl…
Browse files Browse the repository at this point in the history
…ass names. Update namespaces. Clarify function visibility.
  • Loading branch information
raissanorth committed Jan 16, 2018
1 parent 7c6f33b commit cb12b90
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 33 deletions.
8 changes: 8 additions & 0 deletions .upgrade.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/Extensions/UserFormUseQueuedExportExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class UserFormUseQueuedExportExtension extends DataExtension
{
function updateCMSFields(FieldList $fields)
public function updateCMSFields(FieldList $fields)
{
$gridField = $fields->fieldByName('Root.Submissions.Submissions');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\GridfieldQueuedExport;
namespace SilverStripe\GridfieldQueuedExport\Forms;

use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
Expand All @@ -9,13 +9,13 @@
use SilverStripe\Forms\GridField\GridField_FormAction;
use SilverStripe\Forms\GridField\GridField_HTMLProvider;
use SilverStripe\Forms\GridField\GridField_URLHandler;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
use Symbiote\QueuedJobs\Services\QueuedJob;
use Symbiote\QueuedJobs\Services\QueuedJobService;
use SilverStripe\GridfieldQueuedExport\Jobs\GenerateCSVJob;

/**
* A button you can add to a GridField to export that GridField as a CSV. Should work with any sized GridField,
Expand Down Expand Up @@ -89,11 +89,11 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat
if ($actionName == 'export') {
return $this->startExport($gridField);
} elseif ($actionName == 'findgridfield') {
return new GridFieldQueuedExportButton_Response($gridField);
return new GridFieldQueuedExportButtonResponse($gridField);
}
}

function startExport($gridField)
public function startExport($gridField)
{
$job = new GenerateCSVJob();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\GridfieldQueuedExport;
namespace SilverStripe\GridfieldQueuedExport\Forms;

use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Control\HTTPResponse;
Expand All @@ -9,7 +9,7 @@
* 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 HTTPResponse
class GridFieldQueuedExportButtonResponse extends HTTPResponse
{
private $gridField;

Expand Down
16 changes: 9 additions & 7 deletions src/GenerateCSVJob.php → src/Jobs/GenerateCSVJob.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\GridfieldQueuedExport;
namespace SilverStripe\GridfieldQueuedExport\Jobs;

use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
Expand All @@ -14,6 +14,8 @@
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
use Symbiote\QueuedJobs\Services\QueuedJob;

use SilverStripe\GridfieldQueuedExport\Forms\GridFieldQueuedExportButtonResponse;

/**
* Iteratively exports GridField data to a CSV file on disk, in order to support large exports.
* The generated file can be downloaded by the user through a CMS UI provided in {@link GridFieldQueuedExportButton}.
Expand Down Expand Up @@ -66,7 +68,7 @@ public function getSignature()
/**
* @param GridField $gridField
*/
function setGridField(GridField $gridField)
public function setGridField(GridField $gridField)
{
$this->GridFieldName = $gridField->getName();
$this->GridFieldURL = $gridField->Link();
Expand All @@ -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.
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions tests/GenerateCSVJobTest.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<?php

namespace SilverStripe\GridfieldQueuedExport;
namespace SilverStripe\GridFieldQueuedExport\Tests;

use SilverStripe\Assets\Filesystem;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\GridfieldQueuedExport\Jobs\GenerateCSVJob;

class GenerateCSVJobTest extends SapphireTest
{

protected static $fixture_file = 'GenerateCSVJobTest.yml';

protected $extraDataObjects = array(GenerateCSVJobTest_Record::class);
protected $extraDataObjects = array(GenerateCSVJobTestRecord::class);

public function setUp()
{
parent::setUp();
Config::inst()->update(Director::class, 'rules', array(
'jobtest//$Action/$ID/$OtherID' => GenerateCSVJobTest_Controller::class
'jobtest//$Action/$ID/$OtherID' => GenerateCSVJobTestController::class
));
}

Expand All @@ -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');

Expand Down Expand Up @@ -83,4 +84,3 @@ protected function createJob($gridField, $session)
return $job;
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

namespace SilverStripe\GridfieldQueuedExport;

namespace SilverStripe\GridFieldQueuedExport\Tests;

use SilverStripe\Control\Controller;
use SilverStripe\Dev\TestOnly;
Expand All @@ -11,12 +10,9 @@
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Forms\GridField\GridFieldExportButton;

use SilverStripe\GridfieldQueuedExport\GridFieldQueuedExportButton;



use SilverStripe\GridfieldQueuedExport\Forms\GridFieldQueuedExportButton;

class GenerateCSVJobTest_Controller extends Controller implements TestOnly
class GenerateCSVJobTestController extends Controller implements TestOnly
{
private static $allowed_actions = array('Form');

Expand All @@ -28,7 +24,7 @@ public function Link()
public function Form()
{
// Get records
$records = GenerateCSVJobTest_Record::get();
$records = GenerateCSVJobTestRecord::get();

// Set config
$config = GridFieldConfig_RecordEditor::create();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<?php

namespace SilverStripe\GridfieldQueuedExport;

namespace SilverStripe\GridFieldQueuedExport\Tests;

use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;



class GenerateCSVJobTest_Record extends \SilverStripe\ORM\DataObject implements TestOnly
class GenerateCSVJobTestRecord extends DataObject implements TestOnly
{

private static $summary_fields = array(
'Title',
'Content',
Expand Down

0 comments on commit cb12b90

Please sign in to comment.