Skip to main content

EASY Content Server

Vor der Übergabe eines Dokumentes an den EASY Content Server ist es möglich das Schema sowie Feldwerte und Anlagen zu modifizieren oder zu ergänzen. Hier ein Beispiel für ein UserExit:

<?php

use Squeeze\xDoc;
use Squeeze\xReturnObject;

// vor Sqeeze 2.5: BeforeExportEasyContentServer statt BeforeEasyContentServerExport
function BeforeEasyContentServerExport(xDoc $doc, stdClass $ecsRecord): xReturnObject
{
    try {
        // Create a logger instance (optional)
        $logger = Logger::getLogger("main");
      
        // get the Squeeze field with the name "Company"
		$company = $doc->getFieldByName('Company');
		if($company === null) {
            // return an error if the Squeeze field does not exist
			return new xReturnObject(false, 500, 'Field Company does not exist', $ecsRecord);
		}
		
        // If the value of the field Company is equal 1000
		if($company->getValue()->value == '1000') {
            
            // Change the schema to be Test
            $ecsRecord->store = 'Test';
            
            // Modify the document field value to "TestValue" for the field with the name "TestField"
            $ecsRecord->fields['TestField'] = 'TestValue';
          
		} else {
            // return an error if the field Company is not equal 1000
            return new xReturnObject(false, 500, 'Company ' . $company->getValue()->value . ' is invalid', $ecsRecord);
        }

        // return a new result with the modified $ecsRecord variable
        return new xReturnObject(true, 200, 'UserExit BeforeExportEasyContentServer successful', $ecsRecord);

    } catch (Exception $e) {
        // in case of an exception return an error
        return new xReturnObject(false, 500, $e->getMessage(), $ecsRecord);
    }
}