Example #1
0
 public function savePerPageDiscussionEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $siteId = $site->getSiteId();
     $json = new JSONService(SERVICES_JSON_LOOSE_TYPE);
     $cats0 = $json->decode($pl->getParameterValue("categories"));
     $db = Database::connection();
     $db->begin();
     $outdater = new Outdater();
     foreach ($cats0 as $category) {
         $categoryId = $category['category_id'];
         $c = new Criteria();
         $c->add("category_id", $categoryId);
         $c->add("site_id", $siteId);
         // for sure ;-)
         $dCategory = DB_CategoryPeer::instance()->selectOne($c);
         // now compare
         $changed = false;
         if ($category['per_page_discussion'] !== $dCategory->getPerPageDiscussion()) {
             $dCategory->setPerPageDiscussion($category['per_page_discussion']);
             $changed = true;
         }
         if ($changed) {
             $dCategory->save();
             // outdate category too
             $outdater->categoryEvent("category_save", $dCategory);
         }
     }
     $outdater->forumEvent("outdate_forum");
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }
Example #2
0
 public function deletePostEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $postId = $pl->getParameterValue("postId");
     if ($postId == null || !is_numeric($postId)) {
         throw new ProcessException(_("No such post."), "no_post");
     }
     $db = Database::connection();
     $db->begin();
     $post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId);
     if ($post == null || $post->getSiteId() != $site->getSiteId()) {
         throw new ProcessException(_("No such post."), "no_post");
     }
     $thread = $post->getForumThread();
     $category = $thread->getForumCategory();
     try {
         WDPermissionManager::instance()->hasForumPermission('moderate_forum', $runData->getUser(), $category);
     } catch (Exception $e) {
         throw new WDPermissionException(_("Sorry, you are not allowed to delete posts. Only site administrators and moderators are the ones who can."));
     }
     $c = new Criteria();
     $c->add("parent_id", $postId);
     $toDelete = array();
     $chposts = DB_ForumPostPeer::instance()->select($c);
     while ($chposts && count($chposts) > 0) {
         $toDelete = array_merge($toDelete, $chposts);
         $c = new Criteria();
         foreach ($chposts as $f) {
             $c->addOr("parent_id", $f->getPostId());
         }
         $chposts = DB_ForumPostPeer::instance()->select($c);
     }
     DB_ForumPostPeer::instance()->deleteByPrimaryKey($post->getPostId());
     foreach ($toDelete as $f) {
         DB_ForumPostPeer::instance()->deleteByPrimaryKey($f->getPostId());
     }
     // now recalculate a few things...
     $thread->calculateNumberPosts();
     $thread->findLastPost();
     $thread->save();
     $category->calculateNumberPosts();
     $category->findLastPost();
     $category->save();
     // outdate
     $o = new Outdater();
     $o->forumEvent("thread_save", $thread);
     // index thread
     Indexer::instance()->indexThread($thread);
     EventLogger::instance()->logPostDelete($thread, $post->getTitle());
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }