grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026getLockFile(); $this->logger->debug("Reading lock file $filename"); if (!$this->checkFile($filename)) { return false; } $data = file_get_contents($filename); $data = intval($data); if (empty($data)) { $this->logger->warn('Failed to read lock file. Returning \'false\'.'); return false; } $carbon = Carbon::createFromTimestamp($data); $this->logger->debug(sprintf("Last logged indexing performed on %s (%s)", $carbon->toDateTimeString(), $carbon->diffForHumans())); return $carbon; } /** * Gets the lock file name based on the class name. * * @return string */ private function getLockFile() { $cacheFolder = 'cache'; try { $name = (new \ReflectionClass($this))->getShortName(); } catch (\ReflectionException $exception) { $name = str_replace('\\', '.', get_class($this)); } $file = sprintf('%s/%s.lock', $cacheFolder, $name); return $file; } /** * Checks if the file is readable. * * @param string $filename * * @return bool */ private function checkFile($filename) { if (!file_exists($filename)) { $this->logger->debug('Lock file not found'); return false; } if (!is_readable($filename)) { $this->logger->error('Lock file not readable'); return false; } return true; } /** Writes the lock file with the current timestamp to the default location */ private function writeLockFile() { $filename = $this->getLockFile(); $this->logger->debug('Writing lock file to ' . $filename); if (file_exists($filename) && !is_writable($filename)) { $this->logger->error('Lock file not writable'); return; } try { $result = file_put_contents($filename, Carbon::now()->timestamp); if ($result === false) { throw new \RuntimeException('Failed to write lock file!'); } } catch (\Exception $exception) { $this->logger->error('Error while writing lock file'); $this->logger->error($exception); } } }