Source of file ElasticSearchPage_Validator.php
Size: 2,803 Bytes - Last Modified: 2021-12-23T10:58:34+00:00
/var/www/docs.ssmods.com/process/src/searchpage/ElasticSearchPage_Validator.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 | <?php class ElasticSearchPage_Validator extends RequiredFields { protected $customRequired = array('Name'); /** * Constructor. */ public function __construct() { $required = array('ResultsPerPage', 'Identifier'); parent::__construct($required); } public function php($data) { parent::php($data); $valid = true; //Debug::message("Validating data: " . print_r($data, true)); $valid = parent::php($data); //Debug::message("Returning false, just to check"); //return false; // if ($data['ClassesToSearch'] == array()) { $data['ClassesToSearch'] = ''; } $debug = $data['SiteTreeOnly']; // Check if any classes to search if site tree only is not ticked if (!$data['SiteTreeOnly']) { if (!$data['ClassesToSearch']) { $valid = false; $this->validationError('ClassesToSearch', "Please provide at least one class to search, or select 'Site Tree Only'", 'error' ); } else { $toSearch = $data['ClassesToSearch']; foreach ($toSearch as $clazz) { try { $instance = Injector::inst()->create($clazz); if (!$instance->hasExtension('SilverStripe\Elastica\Searchable')) { $this->validationError('ClassesToSearch', 'The class '.$clazz.' must have the Searchable extension'); } } catch (ReflectionException $e) { $this->validationError('ClassesToSearch', 'The class '.$clazz.' does not exist', 'error' ); } } } } // Check the identifier is unique $mode = Versioned::get_reading_mode(); $suffix = ''; if ($mode == 'Stage.Live') { $suffix = '_Live'; } $where = 'ElasticSearchPage'.$suffix.'.ID != '.$data['ID']." AND `Identifier` = '".$data['Identifier']."'"; $existing = ElasticSearchPage::get()->where($where)->count(); if ($existing > 0) { $valid = false; $this->validationError('Identifier', 'The identifier '.$data['Identifier'].' already exists', 'error' ); } // Check number of results per page >= 1 if ($data['ResultsPerPage'] <= 0) { $valid = false; $this->validationError('ResultsPerPage', 'Results per page must be >=1', 'error' ); } return $valid; } } |