JobSchedule.php in Job Scheduler 8.3
File
src/Entity/JobSchedule.php
View source
<?php
namespace Drupal\job_scheduler\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
class JobSchedule extends ContentEntityBase implements ContentEntityInterface {
public function setName($name) {
$this
->set('name', $name);
return $this;
}
public function getName() {
return $this
->get('name')->value;
}
public function setType($type) {
$this
->set('type', $type);
return $this;
}
public function getType() {
return $this
->get('type')->value;
}
public function setId($id) {
$this
->set('id', $id);
return $this;
}
public function getId() {
return $this
->get('id')->value;
}
public function setPeriod($period) {
$this
->set('period', $period);
return $this;
}
public function getPeriod() {
return $this
->get('period')->value;
}
public function setCrontab($crontab) {
$this
->set('crontab', $crontab);
return $this;
}
public function getCrontab() {
return $this
->get('crontab')->value;
}
public function setData(array $data) {
$this
->set('data', serialize($data));
return $this;
}
public function getData() {
$data = $this
->get('data')
->getValue();
return reset($data);
}
public function setPeriodic($periodic) {
$this
->set('periodic', (bool) $periodic);
return $this;
}
public function getPeriodic() {
return (bool) $this
->get('periodic')->value;
}
public function setLast($last) {
$this
->set('last', $last);
return $this;
}
public function getLast() {
return $this
->get('last')->value;
}
public function setNext($next) {
$this
->set('next', $next);
return $this;
}
public function getNext() {
return $this
->get('next')->value;
}
public function setScheduled($scheduled) {
$this
->set('scheduled', $scheduled);
return $this;
}
public function getScheduled() {
return $this
->get('scheduled')->value;
}
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['jid'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the job schedule.'))
->setReadOnly(TRUE)
->setSetting('unsigned', TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the job schedule.'))
->setReadOnly(TRUE);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the job.'))
->setRequired(TRUE)
->setSetting('max_length', 128);
$fields['type'] = BaseFieldDefinition::create('string')
->setLabel(t('Type'))
->setDescription(t('The type of the job.'))
->setRequired(TRUE)
->setSetting('max_length', 128);
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Job ID'))
->setDescription(t('The ID of the job.'))
->setRequired(TRUE);
$fields['period'] = BaseFieldDefinition::create('integer')
->setLabel(t('Period'))
->setDescription(t('Time period after which job is to be executed.'))
->setDefaultValue(0);
$fields['crontab'] = BaseFieldDefinition::create('string')
->setLabel(t('Crontab'))
->setDescription(t('Crontab line in *NIX format.'));
$fields['data'] = BaseFieldDefinition::create('map')
->setLabel(t('Data'))
->setDescription(t('The arbitrary data for the job.'));
$fields['periodic'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Periodic'))
->setDescription(t('If true job will be automatically rescheduled.'))
->setDefaultValue(FALSE);
$fields['last'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Last execution'))
->setDescription(t('Timestamp when a job was last executed.'));
$fields['next'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Next execution'))
->setDescription(t('Timestamp when a job is to be executed.'));
$fields['scheduled'] = BaseFieldDefinition::create('timestamp')
->setLabel(t('Scheduled'))
->setDescription(t('Timestamp when a job was scheduled.'))
->setDefaultValue(0);
return $fields;
}
}