To test if an object should be skipped a shouldSkip
can be applied to a field configuration.
shouldSkip
should reference a method in the Mapper class or an extension applied to the Mapper class.
Dynamic\Salsify\Model\Mapper.example:
extensions:
- ExampleSkipExtension
mapping:
\Page:
FrontImageID:
salsifyField: Front Image
type: Image
Title:
salsifyField: GTIN Name
shouldSkip: shouldSkip
The skip function is passed the class, database field, filed configuration, and the object data. The skip function should return false if the object should not be skipped, true if it should.
<?php
use SilverStripe\Core\Extension;
/**
* Class TestModification
*/
class ExampleSkipExtension extends Extension
{
/**
* @param string|SilverStripe\ORM\DataObject $class
* @param string $dbField
* @param array $config
* @param array $data
* @return boolean
*/
public function shouldSkip($class, $dbField, $config, $data) {
if ($dbField === 'Title') {
// the salsify field in the config for te field
$salsifyField = $config['salsifyField'];
return $data[$salsifyField] === 'TEST';
}
return false;
}
}
All objects with title fields that use this mapping for \Page
will skip when equal to TEST
.
To silently skip skipSilently
should be set to true on the mapper object.
It must be set per skipped object in the should skip method as it resets to false.
<?php
use SilverStripe\Core\Extension;
/**
* Class TestModification
*/
class ExampleSkipExtension extends Extension
{
/**
* @param string|SilverStripe\ORM\DataObject $class
* @param string $dbField
* @param array $config
* @param array $data
* @return boolean
*/
public function shouldSkip($class, $dbField, $config, $data) {
if ($dbField === 'Title') {
// the salsify field in the config for te field
$salsifyField = $config['salsifyField'];
// skip silently
$this->owner->skipSilently = true;
return $data[$salsifyField] === 'TEST';
}
return false;
}
}
To prevent automatically skipping up to date objects skipUpToDate
needs to be set to false in the mapper's config.
Dynamic\Salsify\Model\Mapper.example:
extensions:
- ExampleSkipExtension
skipUpToDate: false
mapping:
\Page:
FrontImageID:
salsifyField: Front Image
type: Image
Title: GTIN Name