class GenerateCSVJob extends AbstractQueuedJob (View source)

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 GridFieldQueuedExportButton.

Simulates a request to the GridFieldQueuedExportButton controller to retrieve the GridField instance, from which the original data context can be derived (as an {@link SS_List instance). This is a necessary workaround due to the limitations on serialising GridField's data description logic. While a DataList is serialisable, other SS_List instances might not be. We'd also need to consider custom value transformations applied via GridField->customDataFields lambdas.

Relies on GridField being accessible in its original CMS controller context to the user who triggered the export.

Traits

Provides extensions to this object to integrate it with standard config API methods.

Config options

sync_sleep_seconds int

Optionally define the number of seconds to wait after the job has finished before marking it as complete.

chunk_size int
permission_mode string
ignore_umask bool

Properties

protected stdClass $jobData from  AbstractQueuedJob
protected array $messages from  AbstractQueuedJob
protected int $totalSteps from  AbstractQueuedJob
protected int $currentStep from  AbstractQueuedJob
protected bool $isComplete from  AbstractQueuedJob
protected $writer

Methods

public
__construct()

Extensions can have a construct but don't have too.

public
string
getTitle()

No description

protected
setObject(DataObject $object, string $name = 'Object')

Sets a data object for persisting by adding its id and type to the serialised vars

protected
DataObject|null
getObject(string $name = 'Object')

No description

public
string
getSignature()

No description

protected
string
randomSignature()

Generate a somewhat random signature

public
getJobType()

No description

public
int|null
getRunAsMemberID()

Specifies what user ID should be when running the job valid values: null - (default) - run the job as current user 0 - run the job without a user greater than zero - run the job as a specific user

public
setup()

Performs setup tasks the first time this job is run.

public
prepareForRestart()

Run when an already setup job is being restarted.

public
process()

Generate export fields for CSV.

public
jobFinished()

Method for determining whether the job is finished - you may override it if there's more to it than just this

public
afterComplete()

Called when the job is determined to be 'complete'

public
getJobData()

No description

public
setJobData(int $totalSteps, int $currentStep, bool $isComplete, stdClass $jobData, array $messages)

No description

public
array|null
getCustomConfig()

Gets custom config settings to use when running the job.

public
setCustomConfig(array $config)

Sets custom config settings to use when the job is run.

public
addMessage(string $message, string $severity = 'INFO')

No description

public
__set(mixed $name, mixed $value)

Convenience methods for setting and getting job data

public
mixed
__get(mixed $name)

Retrieve some job data

public static 
string|null
getQueue(string|int $queue)

Resolves a queue name to one of the queue constants.

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

public
setGridField(GridField $gridField)

No description

public
setSession(array $session)

No description

public
setColumns($columns)

No description

public
setSeparator($seperator)

No description

public
setIncludeHeader($includeHeader)

No description

protected
makeDir($path)

No description

protected
getOutputPath()

No description

protected
Writer
getCSVWriter()

No description

protected
getGridField()

No description

protected
outputHeader($gridField, $columns)

No description

protected
outputRows(GridField $gridField, array $columns, int $start, int $count)

This method is adapted from GridField->generateExportFileData()

protected
initRequest()

Normally Director::handleRequest will register an HTTPRequest service (when routing via frontend controllers).

Details

__construct()

Extensions can have a construct but don't have too.

Without a construct, it's impossible to create a job in the CMS

string getTitle()

No description

Return Value

string

protected setObject(DataObject $object, string $name = 'Object')

Sets a data object for persisting by adding its id and type to the serialised vars

Parameters

DataObject $object
string $name

A name to give it, if you want to store more than one

protected DataObject|null getObject(string $name = 'Object')

No description

Parameters

string $name

Return Value

DataObject|null

string getSignature()

No description

Return Value

string

protected string randomSignature()

Generate a somewhat random signature

useful if you're want to make sure something is always added

Return Value

string

getJobType()

No description

int|null getRunAsMemberID()

Specifies what user ID should be when running the job valid values: null - (default) - run the job as current user 0 - run the job without a user greater than zero - run the job as a specific user

This is useful in situations like:

  • a job needs to always run without a user (like a static cache job)
  • a job needs to run as a specific user (for example data migration job)

Note that this value can be overridden in the QueuedJobService::queueJob()

Return Value

int|null

setup()

Performs setup tasks the first time this job is run.

This is only executed once for every job. If you want to run something on every job restart, use the prepareForRestart method.

prepareForRestart()

Run when an already setup job is being restarted.

process()

Generate export fields for CSV.

jobFinished()

Method for determining whether the job is finished - you may override it if there's more to it than just this

afterComplete()

Called when the job is determined to be 'complete'

getJobData()

No description

setJobData(int $totalSteps, int $currentStep, bool $isComplete, stdClass $jobData, array $messages)

No description

Parameters

int $totalSteps
int $currentStep
bool $isComplete
stdClass $jobData
array $messages

array|null getCustomConfig()

Gets custom config settings to use when running the job.

Return Value

array|null

setCustomConfig(array $config)

Sets custom config settings to use when the job is run.

Parameters

array $config

addMessage(string $message, string $severity = 'INFO')

No description

Parameters

string $message
string $severity

__set(mixed $name, mixed $value)

Convenience methods for setting and getting job data

Parameters

mixed $name
mixed $value

mixed __get(mixed $name)

Retrieve some job data

Parameters

mixed $name

Return Value

mixed

static string|null getQueue(string|int $queue)

Resolves a queue name to one of the queue constants.

If $queue is already the value of one of the constants, it will be returned. If the queue is unknown, null will be returned.

Parameters

string|int $queue

Return Value

string|null

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

setGridField(GridField $gridField)

No description

Parameters

GridField $gridField

setSession(array $session)

No description

Parameters

array $session

setColumns($columns)

No description

Parameters

$columns

setSeparator($seperator)

No description

Parameters

$seperator

setIncludeHeader($includeHeader)

No description

Parameters

$includeHeader

protected makeDir($path)

No description

Parameters

$path

protected getOutputPath()

No description

protected Writer getCSVWriter()

No description

Return Value

Writer

protected GridField getGridField()

No description

Return Value

GridField

Exceptions

HTTPResponse_Exception

protected outputHeader($gridField, $columns)

No description

Parameters

$gridField
$columns

protected outputRows(GridField $gridField, array $columns, int $start, int $count)

This method is adapted from GridField->generateExportFileData()

Parameters

GridField $gridField
array $columns
int $start
int $count

protected initRequest()

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.