/** * Initialize. * * @param string|null $statusFilePath * @param string|null $logFilePath * @param string|null $updateInProgressFlagFilePath * @param string|null $updateErrorFlagFilePath */ public function __construct($statusFilePath = null, $logFilePath = null, $updateInProgressFlagFilePath = null, $updateErrorFlagFilePath = null) { $this->statusFilePath = $statusFilePath ? $statusFilePath : MAGENTO_BP . '/var/.update_status.txt'; $this->logFilePath = $logFilePath ? $logFilePath : MAGENTO_BP . '/var/log/update.log'; $this->updateInProgressFlagFilePath = $updateInProgressFlagFilePath ? $updateInProgressFlagFilePath : MAGENTO_BP . '/var/.update_in_progress.flag'; $this->updateErrorFlagFilePath = $updateErrorFlagFilePath ? $updateErrorFlagFilePath : MAGENTO_BP . '/var/.update_error.flag'; $updateLoggerFactory = new UpdateLoggerFactory(); $this->logger = $updateLoggerFactory->create(); }
/** * Run Cron job readiness check * * @return bool */ public function runReadinessCheck() { $resultJsonRawData = ['readiness_checks' => []]; $success = true; $permissionInfo = $this->checkPermissionsRecursively(); if ($permissionInfo->containsPaths()) { $error = ''; if (!empty($permissionInfo->getNonWritablePaths())) { $error .= '<br/>Found non-writable path(s):<br/>' . implode('<br/>', $permissionInfo->getNonWritablePaths()); } if (!empty($permissionInfo->getNonReadablePaths())) { $error .= '<br/>Found non-readable path(s):<br/>' . implode('<br/>', $permissionInfo->getNonReadablePaths()); } $resultJsonRawData[self::KEY_READINESS_CHECKS][self::KEY_ERROR] = $error; $resultJsonRawData[self::KEY_READINESS_CHECKS][self::KEY_FILE_PERMISSIONS_VERIFIED] = false; $success = false; } else { $resultJsonRawData[self::KEY_READINESS_CHECKS][self::KEY_FILE_PERMISSIONS_VERIFIED] = true; } if (file_exists(MAGENTO_BP . '/var/' . self::CRON_JOB_STATUS_FILE)) { $jsonData = json_decode(file_get_contents(MAGENTO_BP . '/var/' . self::CRON_JOB_STATUS_FILE), true); if (isset($jsonData[self::KEY_CURRENT_TIMESTAMP])) { $resultJsonRawData[self::KEY_LAST_TIMESTAMP] = $jsonData[self::KEY_CURRENT_TIMESTAMP]; } } $resultJsonRawData[self::KEY_CURRENT_TIMESTAMP] = time(); $resultJson = json_encode($resultJsonRawData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); file_put_contents(MAGENTO_BP . '/var/' . self::CRON_JOB_STATUS_FILE, $resultJson); // If non-accessible paths are found, log an 'error' entry for the same in update.log if (!$success) { $outputString = 'Cron readiness check failure! Found following non-writable paths' . PHP_EOL; $outputString .= "\t" . implode(PHP_EOL . "\t", $nonWritablePaths); $updateLoggerFactory = new UpdateLoggerFactory(); $logger = $updateLoggerFactory->create(); $logger->log(\Psr\Log\LogLevel::ERROR, $outputString); } return $success; }