Exemplo n.º 1
0
 /**
  * Returns an instance of class (singleton pattern implementation).
  *
  * @return YNMEDIAIMPORTER_BOL_NodeDao
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 public function deleteNodes($idList)
 {
     if (count($idList) > 0) {
         YNMEDIAIMPORTER_BOL_NodeDao::getInstance()->deleteByIdList($idList);
     }
 }