Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Cron Class Reference
Inheritance diagram for Cron:
Value AbstractModel ValueInterface DataObject

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\App\Config\ValueFactory $configValueFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, $runModelPath='', array $data=[])
 
 afterSave ()
 
- Public Member Functions inherited from Value
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 isValueChanged ()
 
 getOldValue ()
 
 getFieldsetDataValue ($key)
 
 afterSave ()
 
 afterDelete ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const CRON_STRING_PATH = 'crontab/default/jobs/system_backup/schedule/cron_expr'
 
const CRON_MODEL_PATH = 'crontab/default/jobs/system_backup/run/model'
 
const XML_PATH_BACKUP_ENABLED = 'groups/backup/fields/enabled/value'
 
const XML_PATH_BACKUP_TIME = 'groups/backup/fields/time/value'
 
const XML_PATH_BACKUP_FREQUENCY = 'groups/backup/fields/frequency/value'
 
- Data Fields inherited from ValueInterface
const ENTITY = 'config_data'
 

Protected Attributes

 $_configValueFactory
 
 $_runModelPath = ''
 
- Protected Attributes inherited from Value
 $_eventPrefix = 'config_data'
 
 $_eventObject = 'config_data'
 
 $_config
 
 $cacheTypeList
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Backup by cron backend model @api

Since
100.0.2

Definition at line 13 of file Cron.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\App\Config\ScopeConfigInterface  $config,
\Magento\Framework\App\Cache\TypeListInterface  $cacheTypeList,
\Magento\Framework\App\Config\ValueFactory  $configValueFactory,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
  $runModelPath = '',
array  $data = [] 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\App\Config\ScopeConfigInterface$config
\Magento\Framework\App\Cache\TypeListInterface$cacheTypeList
\Magento\Framework\App\Config\ValueFactory$configValueFactory
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
string$runModelPath
array$data

Definition at line 46 of file Cron.php.

56  {
57  $this->_runModelPath = $runModelPath;
58  $this->_configValueFactory = $configValueFactory;
59  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
60  }
$config
Definition: fraud_order.php:17
$resource
Definition: bulk.php:12

Member Function Documentation

◆ afterSave()

afterSave ( )

Cron settings after save

Returns
$this
Exceptions

Definition at line 68 of file Cron.php.

69  {
70  $enabled = $this->getData(self::XML_PATH_BACKUP_ENABLED);
71  $time = $this->getData(self::XML_PATH_BACKUP_TIME);
72  $frequency = $this->getData(self::XML_PATH_BACKUP_FREQUENCY);
73 
74  $frequencyWeekly = \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY;
75  $frequencyMonthly = \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY;
76 
77  if ($enabled) {
78  $cronExprArray = [
79  (int) $time[1], # Minute
80  (int) $time[0], # Hour
81  $frequency == $frequencyMonthly ? '1' : '*', # Day of the Month
82  '*', # Month of the Year
83  $frequency == $frequencyWeekly ? '1' : '*', # Day of the Week
84  ];
85  $cronExprString = join(' ', $cronExprArray);
86  } else {
87  $cronExprString = '';
88  }
89 
90  try {
91  $this->_configValueFactory->create()->load(
92  self::CRON_STRING_PATH,
93  'path'
94  )->setValue(
95  $cronExprString
96  )->setPath(
97  self::CRON_STRING_PATH
98  )->save();
99 
100  $this->_configValueFactory->create()->load(
101  self::CRON_MODEL_PATH,
102  'path'
103  )->setValue(
104  $this->_runModelPath
105  )->setPath(
106  self::CRON_MODEL_PATH
107  )->save();
108  } catch (\Exception $e) {
109  throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t save the Cron expression.'));
110  }
111  return parent::afterSave();
112  }
getData($key='', $index=null)
Definition: DataObject.php:119
__()
Definition: __.php:13

Field Documentation

◆ $_configValueFactory

$_configValueFactory
protected

Definition at line 28 of file Cron.php.

◆ $_runModelPath

$_runModelPath = ''
protected

Definition at line 33 of file Cron.php.

◆ CRON_MODEL_PATH

const CRON_MODEL_PATH = 'crontab/default/jobs/system_backup/run/model'

Definition at line 17 of file Cron.php.

◆ CRON_STRING_PATH

const CRON_STRING_PATH = 'crontab/default/jobs/system_backup/schedule/cron_expr'

Definition at line 15 of file Cron.php.

◆ XML_PATH_BACKUP_ENABLED

const XML_PATH_BACKUP_ENABLED = 'groups/backup/fields/enabled/value'

Definition at line 19 of file Cron.php.

◆ XML_PATH_BACKUP_FREQUENCY

const XML_PATH_BACKUP_FREQUENCY = 'groups/backup/fields/frequency/value'

Definition at line 23 of file Cron.php.

◆ XML_PATH_BACKUP_TIME

const XML_PATH_BACKUP_TIME = 'groups/backup/fields/time/value'

Definition at line 21 of file Cron.php.


The documentation for this class was generated from the following file: