Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CronScriptReadinessCheck.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Setup\Model;
7 
11 
20 {
24  const SETUP = 'setup';
25 
29  const UPDATER = 'updater';
30 
34  const UPDATER_CRON_JOB_STATS_FILE = '.update_cronjob_status';
35 
39  const UPDATER_KEY_FILE_PERMISSIONS_VERIFIED = 'file_permissions_verified';
40 
45  '<br/>Other checks will fail as a result (PHP version, PHP settings, and PHP extensions)';
46 
50  private $filesystem;
51 
57  public function __construct(Filesystem $filesystem)
58  {
59  $this->filesystem = $filesystem;
60  }
61 
67  public function checkSetup()
68  {
69  return $this->checkJson(self::SETUP);
70  }
71 
77  public function checkUpdater()
78  {
79  return $this->checkJson(self::UPDATER);
80  }
81 
88  private function checkJson($type)
89  {
90  $read = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
91  try {
92  switch ($type) {
93  case self::SETUP:
95  $jsonData = json_decode($read->readFile(ReadinessCheck::SETUP_CRON_JOB_STATUS_FILE), true);
96  break;
97  case self::UPDATER:
99  $jsonData = json_decode($read->readFile(self::UPDATER_CRON_JOB_STATS_FILE), true);
100  break;
101  default:
102  return ['success' => false, 'error' => 'Internal Error'];
103  }
104  } catch (\Magento\Framework\Exception\FileSystemException $e) {
105  $error = 'Cron job has not been configured yet';
106  if ($type == self::SETUP) {
108  }
109  return [
110  'success' => false,
111  'error' => $error
112  ];
113  }
114 
115  if (isset($jsonData[ReadinessCheck::KEY_READINESS_CHECKS])
116  && isset($jsonData[ReadinessCheck::KEY_READINESS_CHECKS][$key])
117  ) {
118  if ($jsonData[ReadinessCheck::KEY_READINESS_CHECKS][$key]) {
119  return $this->checkCronTime($jsonData);
120  }
121  return ['success' => false, 'error' => $jsonData[ReadinessCheck::KEY_READINESS_CHECKS]['error']];
122  }
123  $error = 'Cron job has not been configured yet';
124  if ($type == self::SETUP) {
126  }
127  return [
128  'success' => false,
129  'error' => $error
130  ];
131  }
132 
139  private function checkCronTime(array $jsonData)
140  {
141  if (isset($jsonData[ReadinessCheck::KEY_CURRENT_TIMESTAMP])
142  && isset($jsonData[ReadinessCheck::KEY_LAST_TIMESTAMP])
143  ) {
144  $timeDifference = $jsonData[ReadinessCheck::KEY_CURRENT_TIMESTAMP] -
146  if ($timeDifference < 90) {
147  return ['success' => true];
148  }
149  return [
150  'success' => true,
151  'notice' => 'We recommend you schedule cron to run every 1 minute'
152  ];
153  }
154  return [
155  'success' => true,
156  'notice' => 'Unable to determine cron time interval. ' .
157  'We recommend you schedule cron to run every 1 minute'
158  ];
159  }
160 }
$type
Definition: item.phtml:13
$filesystem