In this simple example system activity variables are theoretically unnecessary, since the CSV export of a subtable is completed after one call-up but in more complicated cases it can be necessary to store variables for longer than just the execution time of the system activity. Using a counting variable, which stores the number of system activity call-ups and writes into the log file, the usage of it should be illustrated:
Usage of system activity variables
<?php
class csvSystemActivity extends AbstractSystemActivityAPI
{
...
private $fieldDelimiter;
private $csvFile;
private $csvFilePointer;
private $numberOfRows;
protected function exportCsv()
{
$this->increaseSystemActivityCalls();
$this->debug('exportCsv start');
$this->loadGlobalSettings();
$this->openCsvFile('w');
$this->debug('executeMethodForSubtable for '. $this->getFixSubtableName());
$this->initLineCounter();
$this->executeMethodForSubtable('writeSubtableLineIntoFile', $this->getFixSubtableName());
$this->storeOutputParameter('targetFile', $this->csvFile);
$this->storeOutputParameter('numberOfRows', $this->numberOfRows);
}
protected function increaseSystemActivityCalls()
{
$systemActivityCalls = $this->getSystemActivityVar('systemActivityCalls', 0);
$systemActivityCalls++;
$this->debug('system activity calls: ' . $systemActivityCalls);
$this->setSystemActivityVar('systemActivityCalls', $systemActivityCalls);
}
protected function loadGlobalSettings()
{
$this->fieldDelimiter = $this->resolveInputParameter('fieldDelimiter');
}
protected function openCsvFile($mode)
{
$this->csvFile = $this->getTempPath() . DIRECTORY_SEPARATOR . 'test.csv';
$this->debug('csvFile: '.$this->csvFile);
$this->csvFilePointer = fopen($this->csvFile, $mode);
}
protected function initLineCounter()
{
$this->numberOfRows = 0;
}
protected function writeSubtableLineIntoFile()
{
$this->debug('writeSubtableLineIntoFile for '. $this->getFixSubtableName());
$subtableValues = $this->resolveInputParameterListValues('fieldList');
$csvLine = implode($this->fieldDelimiter, $subtableValues)."\r\n";
fwrite($this->csvFilePointer, $csvLine);
$this->numberOfRows++;
}
}
Each time the system activity is executed, the counting variable is increased by 1. Only when the system activity reaches the status completed (see chapter Changing the step status), the contents of the system activity variable is deleted.