Exemple #1
0
 public function bdSocialShare_actionIcon(XenResource_DataWriter_Resource $resourceDw)
 {
     $resource = $resourceDw->getMergedData();
     $queueDate = $resource['resource_date'] + bdSocialShare_Shareable_XenResource_Resource::SECONDS_WAIT_FOR_ICON;
     $shareQueueModel = $this->getModelFromCache('bdSocialShare_Model_ShareQueue');
     $queue = $shareQueueModel->getQueueAt($queueDate);
     if (!empty($queue)) {
         foreach ($queue as $id => $record) {
             $data = bdSocialShare_Helper_Common::unserializeOrFalse($record, 'queue_data');
             if (!empty($data) and !empty($data['shareable'])) {
                 $shareable = bdSocialShare_Shareable_Abstract::createFromRecoveryData($data['shareable']);
                 if ($shareable instanceof bdSocialShare_Shareable_XenResource_Resource and $shareable->getId() == $resource['resource_id']) {
                     $shareQueueModel->reInsertQueue($record, XenForo_Application::$time);
                 }
             }
         }
     }
     unset($GLOBALS[bdSocialShare_Listener::XENRESOURCE_CONTROLLERPUBLIC_RESOURCE_ICON]);
 }
Exemple #2
0
 public function recover($target, $recovery = false)
 {
     if ($recovery === false) {
         $recovery = $this->loadRecoveryData();
     }
     // reset recovery asap, it will be updated later
     $this->_getPublisherModel()->saveRecoveryData();
     $recovered = true;
     if (empty($recovery) or empty($recovery['shareable']) or empty($recovery['targets'])) {
         return false;
     }
     if (empty($recovery['targets'][$target])) {
         return false;
     }
     $targetId = $recovery['targets'][$target];
     $shareable = bdSocialShare_Shareable_Abstract::createFromRecoveryData($recovery['shareable']);
     if (empty($shareable)) {
         return false;
     }
     try {
         $this->_getPublisherModel()->publish($target, $targetId, $shareable);
         $this->_getPublisherModel()->postPublish($shareable);
         $recovered = true;
     } catch (bdSocialShare_Exception_Abstract $e) {
         if (XenForo_Application::debugMode()) {
             XenForo_Error::logException($e, false);
         }
     }
     if ($recovered) {
         // remove the target from the queue
         unset($recovery['targets'][$target]);
     }
     if (!empty($recovery['targets'])) {
         // still have something in queue, set recovery...
         $this->_getPublisherModel()->saveRecoveryData($recovery['shareable'], $recovery['targets']);
     }
 }
Exemple #3
0
 public function runQueue($targetRunTime = 0)
 {
     $s = microtime(true);
     $db = $this->_getDb();
     do {
         $queue = $this->getQueue($targetRunTime ? 20 : 0);
         foreach ($queue as $id => $record) {
             if (!$db->delete('xf_bdsocialshare_share_queue', 'share_queue_id = ' . $db->quote($id))) {
                 // already been deleted - run elsewhere
                 continue;
             }
             $data = bdSocialShare_Helper_Common::unserializeOrFalse($record, 'queue_data');
             if (empty($data) or empty($data['shareable'])) {
                 if (XenForo_Application::debugMode()) {
                     XenForo_Error::logException(new XenForo_Exception('Insufficient data'), false);
                 }
                 continue;
             }
             $shareable = bdSocialShare_Shareable_Abstract::createFromRecoveryData($data['shareable']);
             if (empty($shareable)) {
                 if (XenForo_Application::debugMode()) {
                     XenForo_Error::logException(new XenForo_Exception('Unable to create shareable from recovery data'), false);
                 }
                 return false;
             }
             $userModel = $this->getModelFromCache('XenForo_Model_User');
             if (!empty($data['user_id'])) {
                 $viewingUser = $userModel->getVisitingUserById($data['user_id']);
             } else {
                 $viewingUser = $userModel->getVisitingGuestUser();
             }
             if (empty($viewingUser)) {
                 if (XenForo_Application::debugMode()) {
                     XenForo_Error::logException(new XenForo_Exception('User could not be found'), false);
                 }
                 return false;
             }
             $userModel->bdSocialShare_prepareViewingUser($viewingUser);
             $this->publish($shareable, $data['targets'], !empty($data['default']), $viewingUser);
             if ($targetRunTime && microtime(true) - $s > $targetRunTime) {
                 $queue = false;
                 break;
             }
         }
     } while ($queue);
     return $this->hasQueue();
 }