Please enable JavaScript to view this site.

Das Handbuch für den JobRouter Entwickler

Navigation: Systemaktivitäten > Verwendung der PHP API am Beispiel CSV-Export > Speichern von Ausgabeparametern und Änderung des Status

Systemaktivitäts-Variablen

Scroll Zurück Oben Weiter Mehr

In diesem einfachen Beispiel werden Systemaktivitätsvariablen eigentlich nicht benötigt, da der CSV-Export einer Untertabelle nach einem Aufruf der Systemaktivität abgeschlossen ist. In komplizierteren Anwendungsfällen kann es aber durchaus vorkommen, dass Variablen über die Laufzeit einer Systemaktivität hinaus gespeichert werden müssen, um Verarbeitung nach und nach zu vervollständigen. Anhand einer Zählvariablen, welche die Anzahl der Aufrufe der Systemaktivität speichert und in die Log-Datei schreibt, soll ihre Verwendung kurz gezeigt werden:

Verwendung von Systemaktivitätsvariablen

<?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++;

    }

}

Bei jedem Ausführen der Systemaktivität wird nun die Zählvariable um 1 erhöht. Erst, wenn die Systemaktivität den Status abgeschlossen erreicht hat (vgl. Abschnitt Ändern des Steo-Status), wird der Inhalt der Systemaktivitätsvariablen gelöscht.