Pimcore\Model\Tool\Lock::acquire PHP Метод

acquire() публичный статический Метод

public static acquire ( string $key, $expire = 120, $refreshInterval = 1 )
$key string
    public static function acquire($key, $expire = 120, $refreshInterval = 1)
    {
        $instance = self::getInstance();
        $instance->getDao()->acquire($key, $expire, $refreshInterval);
        self::$acquiredLocks[$key] = $key;
    }

Usage Example

Пример #1
0
 /**
  * @param $documentId
  * @throws \Exception
  */
 public function startPdfGeneration($documentId)
 {
     $jobConfigFile = $this->loadJobConfigObject($documentId);
     $document = $this->getPrintDocument($documentId);
     // check if there is already a generating process running, wait if so ...
     Model\Tool\Lock::acquire($document->getLockKey(), 0);
     try {
         $pdf = $this->buildPdf($document, $jobConfigFile->config);
         file_put_contents($document->getPdfFileName(), $pdf);
         \Pimcore::getEventManager()->trigger("document.print.postPdfGeneration", $document, ["filename" => $document->getPdfFileName(), "pdf" => $pdf]);
         $creationDate = \Zend_Date::now();
         $document->setLastGenerated($creationDate->get() + 1);
         $document->save();
     } catch (\Exception $e) {
         $document->save();
         \Logger::err($e);
     }
     Model\Tool\Lock::release($document->getLockKey());
     Model\Tool\TmpStore::delete($document->getLockKey());
     @unlink($this->getJobConfigFile($documentId));
 }
All Usage Examples Of Pimcore\Model\Tool\Lock::acquire