示例#1
0
 /**
  * Returns an instance of class (singleton pattern implementation).
  *
  * @return YNMEDIAIMPORTER_BOL_SchedulerDao
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
示例#2
0
文件: cron.php 项目: vazahat/dudex
 public function processScheduler()
 {
     /**
      * following step to speed up & beat performance
      * 1. check album limit
      * 2. check quota limit
      * 3. get nodes of this schedulers
      * 4. get all items of current schedulers.
      * 5. process each node
      * 5.1 check required quota
      * 5.2 fetch data to pubic file
      * 5.3 store to file model
      * 6. check status of schedulers, if scheduler is completed == (remaining == 0)
      * 6.1 udpate feed and message.
      */
     /**
      * Unlimited time.
      */
     set_time_limit(0);
     /**
      * default 20
      * @var int
      */
     $configs = OW::getConfig()->getValues('ynmediaimporter');
     $limitUserPerCron = $configs['number_photo'] ? intval($configs['number_photo']) : 20;
     /**
      * default 20
      * @var int
      */
     $limitQueuePerCron = $configs['number_queue'] ? intval($configs['number_queue']) : 20;
     /**
      * process number queue.
      */
     /**
      * get scheduler from tables data.
      */
     $example = new OW_Example();
     $example->andFieldLessThan('status', '3');
     $example->setOrder('last_run');
     $example->setLimitClause($first, $count)->setLimitClause(0, $limitQueuePerCron);
     $schedulers = YNMEDIAIMPORTER_BOL_SchedulerDao::getInstance()->findListByExample($example);
     foreach ($schedulers as $scheduler) {
         Ynmediaimporter::processScheduler($scheduler, 0, $limitUserPerCron, 1, 1);
     }
     echo "success!";
     exit(0);
 }
示例#3
0
文件: Service.php 项目: vazahat/dudex
 public static function processScheduler($scheduler, $user_aid = null, $limit = 10, $sendNotification = false, $sendActivity = true)
 {
     //register_shutdown_function(array('Ynmediaimporter','handleShutdown'), $scheduler -> id);
     //ini_set('max_execution_time',1);
     $movedCount = 0;
     $movedArray = array();
     $photos = array();
     $schedulerId = $scheduler->id;
     $userId = $scheduler->user_id;
     $user = BOL_UserService::getInstance()->findUserById($userId);
     $album = null;
     $example = new OW_Example();
     $example->andFieldEqual('scheduler_id', $schedulerId);
     $example->andFieldLessThan('status', '3');
     $example->andFieldGreaterThan('status', '0');
     $example->setLimitClause(0, $limit);
     if ($user_aid) {
         $example->andFieldEqual('user_aid', intval($user_aid));
     }
     $nodeList = YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->findListByExample($example);
     $order = 0;
     foreach ($nodeList as $node) {
         if ('photo' == $node->media && $node->user_aid > 0) {
             $album = PHOTO_BOL_PhotoAlbumDao::getInstance()->findById($node->user_aid);
             if (!is_object($album)) {
                 continue;
             }
             //download file
             $dir = Ynmediaimporter::getValidDir();
             $file = $dir . $node->getUUID();
             $privacy = OW::getEventManager()->call('plugin.privacy.get_privacy', array('ownerId' => $album->userId, 'action' => 'photo_view_album'));
             $photo = new PHOTO_BOL_Photo();
             $photo->description = '';
             $photo->albumId = $album->id;
             $photo->addDatetime = time();
             $photo->status = 'approved';
             $photo->hasFullsize = '1';
             $photo->privacy = mb_strlen($privacy) ? $privacy : 'everybody';
             $source = self::saveImageFromUrl($node->getDownloadFilename(), $file);
             $photo = self::__savePhoto($photo, $source, $userId);
             if ($photo) {
                 $photos[] = $photo;
                 $movedArray[] = array('addTimestamp' => time(), 'photoId' => $photo->id);
                 $movedCount++;
             }
             $node->status = 3;
             YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->save($node);
         } else {
             if (in_array($node->media, array('album', 'photoset', 'gallery')) && 0 == $node->user_aid) {
                 // create new albums for this roles
                 $album = self::createPhotoAlbums($scheduler, $node);
                 // setup album and node.
                 // update all sub node of current scheduler to this albums.
                 $example = new OW_Example();
                 $example->andFieldEqual('scheduler_id', $schedulerId);
                 $example->andFieldEqual('aid', $node->aid);
                 $nodeTemp = YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->findObjectByExample($example);
                 $nodeTemp->user_aid = $album->id;
                 $nodeTemp->status = '1';
                 YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->save($nodeTemp);
                 $node->user_aid = $album->id;
                 $node->status = 1;
                 YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->save($node);
                 self::processScheduler($scheduler, $album->id, 10, 0, 0);
                 break;
                 // force process this album to escape no value style.
             }
         }
     }
     $example = new OW_Example();
     $example->andFieldEqual('scheduler_id', $schedulerId);
     $example->andFieldEqual('media', 'photo');
     $example->andFieldLessThan('status', '3');
     $remain = intval(YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->countByExample($example));
     // all scheduler is completed. send notification to users
     if (is_object($album) && $remain == 0) {
         // Send notification
         if ($sendNotification) {
             $actor = array('username' => BOL_UserService::getInstance()->getUserName($userId), 'name' => BOL_UserService::getInstance()->getDisplayName($userId), 'url' => BOL_UserService::getInstance()->getUserUrl($userId));
             $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($userId));
             $event = new OW_Event('notifications.add', array('pluginKey' => 'ynmediaimporter', 'entityType' => 'ynmediaimporter_album', 'entityId' => (int) $album->id, 'action' => 'ynmediaimporter_album-added', 'userId' => $album->userId, 'time' => time()), array('avatar' => $avatars[$userId], 'string' => array('key' => 'ynmediaimporter+added_album_notification_string', 'vars' => array('actor' => $actor['name'], 'actorUrl' => $actor['url'], 'title' => $album->name, 'url' => OW::getRouter()->urlForRoute('photo_user_album', array('user' => $actor['username'], 'album' => $album->id)))), 'content' => $album->name, 'url' => OW::getRouter()->urlForRoute('photo_user_album', array('user' => $actor['username'], 'album' => $album->id))));
             OW::getEventManager()->trigger($event);
         }
         if ($sendActivity) {
             self::__sendActivity($album, $photos, $movedArray, $movedCount);
         }
     }
     $scheduler->status = $remain == 0 ? 3 : 1;
     $scheduler->last_run = time();
     YNMEDIAIMPORTER_BOL_SchedulerDao::getInstance()->save($scheduler);
     // and of process rec count all
     $tableName = OW_DB_PREFIX . 'ynmediaimporter_nodes';
     $sql = "SELECT\n\t\t\t\t  album.id,\n\t\t\t\t  (SELECT\n\t\t\t\t     COUNT( * )\n\t\t\t\t   FROM {$tableName} AS photo\n\t\t\t\t   WHERE photo.media = 'photo'\n\t\t\t\t       AND photo.aid = album.id\n\t\t\t\t       AND photo.status = 1) AS remaining\n\t\t\t\tFROM `{$tableName}` album\n\t\t\t\tWHERE album.media <> 'photo'\n\t\t\t\t    AND album.status = 1\n\t\t\t\tGROUP BY album.id\n\t\t\t\tHAVING remaining = 0";
     $completedList = OW::getDbo()->queryForColumnList($sql);
     if ($completedList) {
         $sql = "UPDATE `{$tableName}` SET `status` = '3' where `id` IN (" . implode(',', $completedList) . ")";
         OW::getDbo()->query($sql);
     }
     return array('remain' => $remain, 'scheduler_id' => $schedulerId);
 }
示例#4
0
 public function deleteSchedulers($idList)
 {
     if (count($idList) > 0) {
         YNMEDIAIMPORTER_BOL_SchedulerDao::getInstance()->deleteByIdList($idList);
     }
 }
示例#5
0
 public function scheduler($params)
 {
     register_shutdown_function(array($this, 'handleShutdown'));
     ini_set('max_execution_time', 12);
     /**
      * following step to speed up & beat performance
      * 1. check album limit
      * 2. check quota limit
      * 3. get nodes of this schedulers
      * 4. get all items of current schedulers.
      * 5. process each node
      * 5.1 check required quota
      * 5.2 fetch data to pubic file
      * 5.3 store to file model
      * 6. check status of schedulers, if scheduler is completed == (remaining == 0)
      * 6.1 udpate feed and message.
      */
     /**
      * Unlimited time.
      */
     //set_time_limit(0);
     $schedulerId = $params['scheduler_id'];
     $scheduler = YNMEDIAIMPORTER_BOL_SchedulerDao::getInstance()->findById($schedulerId);
     /**
      * check Ynmediaimporter::processScheduler for futher information.
      *
      */
     $result = Ynmediaimporter::processScheduler($scheduler, 0, 10, 1, 1);
     /**
      * get remain
      * @see Ynmediaimporter::processScheduler
      */
     $remain = $result['remain'];
     if ($remain == 0) {
         $result['message'] = 'Your import request has been completed.';
     } else {
         $result['message'] = 'Your import request has been added to the queue.';
     }
     echo json_encode($result);
     exit(0);
 }