Example #1
0
 /**
  * Returns time-based + int element string.
  */
 public static function timeBased()
 {
     $timePart = time() . '';
     // TRANSACTION OR TABLE LOCK SHOULD START HERE
     $db = Database::connection();
     $db->begin();
     $c = new Criteria();
     $c->setForUpdate(true);
     $index = DB_UniqueStringBrokerPeer::instance()->selectOne($c);
     if ($index != null) {
         $idx = $index->getLastIndex();
         $number = $idx + 1;
         //update index + 1
         DB_UniqueStringBrokerPeer::instance()->increaseIndex();
     } else {
         $number = 0;
         DB_UniqueStringBrokerPeer::instance()->init();
     }
     $db->commit();
     // TRANSACTION OR TABLE LOCK SHOULD END HERE
     return $timePart . "_" . $number;
 }
Example #2
0
 public function deletePageEvent($runData)
 {
     $pl = $runData->getParameterList();
     $pageId = $pl->getParameterValue("page_id");
     $site = $runData->getTemp("site");
     $db = Database::connection();
     $db->begin();
     $c = new Criteria();
     $c->add("page_id", $pageId);
     $c->setForUpdate(true);
     $page = DB_PagePeer::instance()->selectOne($c);
     if ($page == null || $page->getSiteId() != $site->getSiteId()) {
         throw new ProcessException(_("Error getting page information."), "no_page");
     }
     $user = $runData->getUser();
     $category = $page->getCategory();
     WDPermissionManager::instance()->hasPagePermission('delete', $user, $category, $page);
     // ok, delete... sad but true.
     $deleter = Deleter::instance();
     $deleter->deletePage($page, $site);
     $db->commit();
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }
Example #3
0
 public function saveEditPostEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $title = $pl->getParameterValue("title");
     $source = $pl->getParameterValue("source");
     $threadId = $pl->getParameterValue("threadId");
     $postId = $pl->getParameterValue("postId");
     $currentRevisionId = $pl->getParameterValue("currentRevisionId");
     $user = $runData->getUser();
     $userId = $runData->getUserId();
     if ($userId == null) {
         $userString = $runData->createIpString();
     }
     $errors = array();
     if (strlen8($title) > 128) {
         $errors['title'] = _("Post title should not be longer than 128 characters.");
     }
     if (strlen($source) > 200000) {
         $errors['source'] = _("It seems the source is too long.");
     } elseif ($source == '') {
         $errors['source'] = _("Post body can not be empty.");
     }
     if (count($errors) > 0) {
         $runData->ajaxResponseAdd("formErrors", $errors);
         throw new ProcessException("Form errors", "form_errors");
     }
     $db = Database::connection();
     $db->begin();
     if ($postId == null || !is_numeric($postId)) {
         throw new ProcessException(_("No such post."), "no_post");
     }
     $post = DB_ForumPostPeer::instance()->selectByPrimaryKey($postId);
     if ($post == null || $post->getSiteId() != $site->getSiteId()) {
         throw new ProcessException(_("No such post."), "no_post");
     }
     $c = new Criteria();
     $c->add("thread_id", $post->getThreadId());
     $c->add("site_id", $site->getSiteId());
     $c->setForUpdate(true);
     $thread = DB_ForumThreadPeer::instance()->selectOne($c);
     if ($thread == null || $thread->getSiteId() != $site->getSiteId()) {
         throw new ProcessException("Thread not found.", "no_thread");
     }
     // check revisions...
     if ($post->getRevisionId() != $currentRevisionId) {
         throw new ProcessException(_("The post has been changed meanwhile. Sorry, you can not save it. Please reload the page and start editing again with the current revision... :-("), "no_post");
     }
     $category = $post->getForumThread()->getCategory();
     WDPermissionManager::instance()->hasForumPermission('edit_post', $runData->getUser(), $category, null, $post);
     if ($thread->getBlocked()) {
         // check if moderator or admin
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $c->add("user_id", $user->getUserId());
         $rel = DB_ModeratorPeer::instance()->selectOne($c);
         if (!$rel || strpos($rel->getPermissions(), 'f') == false) {
             $rel = DB_AdminPeer::instance()->selectOne($c);
             if (!$rel) {
                 throw new WDPermissionException(_("Sorry, this thread is blocked. Nobody can  add new posts nor edit existing ones."));
             }
         }
     }
     // compile content
     $wt = new WikiTransformation();
     $wt->setMode('post');
     $body = $wt->processSource($source);
     $postRevision = new DB_ForumPostRevision();
     $postRevision->obtainPK();
     $postRevision->setPostId($post->getPostId());
     $postRevision->setText($source);
     $postRevision->setTitle($title);
     $postRevision->setDate(new ODate());
     $post->setRevisionId($postRevision->getRevisionId());
     $post->setRevisionNumber($post->getRevisionNumber() + 1);
     $post->setText($body);
     $post->setTitle($title);
     $post->setDateLastEdited(new ODate());
     if ($userId) {
         $postRevision->setUserId($userId);
         $post->setEditedUserId($userId);
     } else {
         $postRevision->setUserId(0);
         $post->setEditedUserId(0);
         $postRevision->setUserString($userString);
         $post->setEditedUserString($userString);
     }
     $post->save();
     $postRevision->save();
     $o = new Outdater();
     $o->forumEvent("post_save", $post);
     // index thread
     Indexer::instance()->indexThread($thread);
     EventLogger::instance()->logSavePost($post);
     $db->commit();
     $runData->ajaxResponseAdd("postId", $post->getPostId());
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }