protected function tryLockUpdate()
 {
     $this->getStorageBackend()->lock($this->getBackendStorageSpace(), self::STORAGE_BACKEND_IS_UPDATE_RUNNING_KEY, Customweb_Storage_IBackend::EXCLUSIVE_LOCK);
     $locked = $this->getStorageBackend()->read($this->getBackendStorageSpace(), self::STORAGE_BACKEND_IS_UPDATE_RUNNING_KEY);
     if ($locked == 'yes') {
         $time = $this->getStorageBackend()->read($this->getBackendStorageSpace(), self::STORAGE_BACKEND_LAST_START_UPDATE_KEY);
         if (empty($time)) {
             $time = 0;
         }
         $timeout = Customweb_Util_System::getMaxExecutionTime() * 2;
         if ($time + $timeout < time()) {
             $success = true;
         } else {
             $success = false;
         }
     } else {
         $success = true;
     }
     if ($success) {
         $this->getStorageBackend()->write($this->getBackendStorageSpace(), self::STORAGE_BACKEND_LAST_START_UPDATE_KEY, time());
         $this->getStorageBackend()->write($this->getBackendStorageSpace(), self::STORAGE_BACKEND_IS_UPDATE_RUNNING_KEY, 'yes');
     }
     $this->getStorageBackend()->unlock($this->getBackendStorageSpace(), self::STORAGE_BACKEND_IS_UPDATE_RUNNING_KEY);
     return $success;
 }
 /**
  * @see Customweb_Payment_Update_AbstractProcessor::process()
  * @Cron()
  */
 public function process()
 {
     if ($this->getUpdateAdapter() === null) {
         return;
     }
     if (!$this->tryLockUpdate()) {
         return;
     }
     $approximatelyExecutedTime = 4;
     $maxExecutionTime = Customweb_Util_System::getMaxExecutionTime() - $approximatelyExecutedTime;
     $start = $this->getStartTime();
     $maxEndtime = $maxExecutionTime + $start;
     try {
         $candidates = $this->getHandler()->getScheduledTransactionIds();
         foreach ($candidates as $transactionId) {
             if ($maxEndtime > time()) {
                 $this->executeUpdate($transactionId);
             } else {
                 break;
             }
         }
     } catch (Exception $e) {
         $this->getHandler()->log("Failed to load scheduled transactions: " . $e->getMessage(), Customweb_Payment_Update_IHandler::LOG_TYPE_ERROR);
     }
     $this->unlockUpdate();
 }
Example #3
0
 /**
  * Execute all cron jobs.
  * 
  * @throws Exception In case something went wrong.
  */
 public function run()
 {
     $scanner = new Customweb_Annotation_Scanner();
     $annotations = $scanner->find('Customweb_Cron_Annotation_Cron', $this->packages);
     $approxFinalizeTime = 4;
     $maxExecutionTime = Customweb_Util_System::getMaxExecutionTime() - $approxFinalizeTime;
     $start = $this->getStartTime();
     $endTime = $start + $maxExecutionTime;
     foreach ($annotations as $identifier => $annotation) {
         if ($endTime < time()) {
             break;
         }
         if ($annotation instanceof Customweb_Cron_Annotation_Cron) {
             $parts = explode('::', $identifier, 2);
             $className = $parts[0];
             $methodName = $parts[1];
             $this->invoke($className, $methodName, $annotation);
         }
     }
 }
Example #4
0
 /**
  * @param string $transactionId
  * @return string
  */
 public function waitForNotification($transaction)
 {
     if (Mage::getStoreConfig('saferpaycw/general/wait_for_success') != '1') {
         $transaction->getOrder()->getPayment()->getMethodInstance()->success($transaction, $_REQUEST);
         return $this->getSuccessUrl($transaction);
     }
     $transactionId = $transaction->getId();
     $maxTime = min(array(Customweb_Util_System::getMaxExecutionTime() - 4, 30));
     $startTime = microtime(true);
     while (true) {
         if (microtime(true) - $startTime >= $maxTime) {
             break;
         }
         $transaction = Mage::getModel('saferpaycw/transaction')->load($transactionId);
         if ($transaction == null || !$transaction->getId() || $transaction->getTransactionObject() == null) {
             continue;
         }
         if ($transaction->getTransactionObject()->isAuthorized()) {
             $transaction->getOrder()->getPayment()->getMethodInstance()->success($transaction, $_REQUEST);
             return $this->getSuccessUrl($transaction);
         }
         if ($transaction->getTransactionObject()->isAuthorizationFailed()) {
             $errorMessages = $transaction->getTransactionObject()->getErrorMessages();
             $messageToDisplay = nl2br(end($errorMessages));
             reset($errorMessages);
             $transaction->getOrder()->getPayment()->getMethodInstance()->fail($transaction, $_REQUEST);
             return $this->getFailUrl($transaction);
         }
         sleep(1);
     }
     $transaction->getOrder()->getPayment()->getMethodInstance()->success($transaction, $_REQUEST);
     Mage::getSingleton('core/session')->addError($this->__('There has been a problem during the processing of your payment. Please contact the shop owner to make sure your order was placed successfully.'));
     return $this->getSuccessUrl($transaction);
 }