当前位置: 首页>>代码示例>>PHP>>正文


PHP Forum::write方法代码示例

本文整理汇总了PHP中Forum::write方法的典型用法代码示例。如果您正苦于以下问题:PHP Forum::write方法的具体用法?PHP Forum::write怎么用?PHP Forum::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Forum的用法示例。


在下文中一共展示了Forum::write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 function run($request)
 {
     set_time_limit(0);
     // check to see if this has been run before. If it has then we will have already
     // have removed the parentID field
     $checkForMigration = DB::query("SHOW COLUMNS FROM \"Post\"")->column();
     if (!in_array('ParentID', $checkForMigration)) {
         echo "Script has already ran. You can only run the migration script once.\n";
         return false;
     }
     // go through all the posts with a parent ID = 0 and create the new thread objects
     $oldThreads = DB::query("SELECT * FROM \"Post\" WHERE \"ParentID\" = '0'");
     if ($oldThreads) {
         $toCreateTotal = $oldThreads->numRecords();
         echo "Creating " . $toCreateTotal . " new Forum Threads \n";
         $holder = DataObject::get_one("ForumHolder");
         if (!$holder) {
             return user_error('No Forum Holder Found', E_USER_ERROR);
         }
         $failbackForum = new Forum();
         $failbackForum->Title = "Unimported Threads";
         $failbackForum->ParentID = $holder->ID;
         $failbackForum->write();
         $needsFailback = false;
         $totalThreadsSuccessfulCount = 0;
         $totalThreadsErroredCount = 0;
         while ($oldThread = $oldThreads->nextRecord()) {
             $hasError = false;
             $thread = new ForumThread();
             if (isset($oldThread['Title'])) {
                 $thread->Title = $oldThread['Title'];
             } else {
                 $hasError = true;
                 $thread->Title = "Question";
             }
             $thread->NumViews = isset($oldThread['NumViews']) ? $oldThread['NumViews'] : 0;
             $thread->IsSticky = isset($oldThread['IsSticky']) ? $oldThread['IsSticky'] : false;
             $thread->IsReadOnly = isset($oldThread['IsReadOnly']) ? $oldThread['IsReadOnly'] : false;
             $thread->IsGlobalSticky = isset($oldThread['IsGlobalSticky']) ? $oldThread['IsGlobalSticky'] : false;
             if (isset($oldThread['ForumID'])) {
                 $thread->ForumID = $oldThread['ForumID'];
             } else {
                 $hasError = true;
                 $needsFailback = true;
                 $thread->ForumID = $failbackForum->ID;
             }
             $thread->write();
             echo "Converted Thread: {$thread->ID} - {$thread->Title}. \n";
             // update all the children
             DB::query("\n\t\t\t\t\tUPDATE \"Post\" \n\t\t\t\t\tSET \"ThreadID\" = '{$thread->ID}', \"ForumID\" = '{$thread->ForumID}'\n\t\t\t\t\tWHERE \"TopicID\" = '" . $oldThread['ID'] . "'\n\t\t\t\t");
             if (!$hasError) {
                 $totalThreadsSuccessfulCount++;
             } else {
                 $totalThreadsErroredCount++;
             }
         }
     }
     echo "Converted {$totalThreadsSuccessfulCount} threads. Could not import {$totalThreadsErroredCount} threads.<br />";
     if (!$needsFailback) {
         $failbackForum->delete();
     } else {
         echo "Incorrectly imported threads are available to self moderate at <a href='" . $failbackForum->Link() . "'>here</a><br />";
     }
     // transfer subscriptions
     // was a rename table but mysql had locking issues.
     $subscriptions = DB::query("SELECT * FROM \"Post_Subscription\"");
     $subCount = 0;
     if ($subscriptions) {
         while ($sub = $subscriptions->nextRecord()) {
             // don't import really odd data
             if (isset($sub['TopicID']) && isset($sub['MemberID'])) {
                 $subCount++;
                 $threadSub = new ForumThread_Subscription();
                 $threadSub->ThreadID = $sub['TopicID'];
                 $threadSub->MemberID = $sub['MemberID'];
                 $threadSub->write();
             }
         }
     }
     echo "Transferred {$subCount} Thread Subscriptions<br />";
     // Update the permissions on the forums. The Posters, Viewers have changed from a int field
     // to an actual modelled relationship
     $forums = DataObject::get('Forum');
     if ($forums) {
         foreach ($forums as $forum) {
             $forum->ForumPostersGroupID = DB::query("SELECT \"ForumPostersGroup\" FROM \"Forum\" WHERE \"ID\" = '{$forum->ID}'")->value();
             if ($viewingGroup = DB::query("SELECT \"ForumViewersGroup\" FROM \"Forum\" WHERE \"ID\" = '{$forum->ID}'")->value()) {
                 $forum->ViewerGroups()->add(DataObject::get_by_id('Group', $viewingGroup));
             }
             $forum->write();
         }
     }
     // cleanup task. Delete old columns which are hanging round
     DB::dontRequireField('Post', 'ParentID');
     DB::dontRequireField('Post', 'TopicID');
     DB::dontRequireField('Post', 'Title');
     DB::dontRequireField('Post', 'NumViews');
     DB::dontRequireField('Post', 'IsSticky');
     DB::dontRequireField('Post', 'IsReadOnly');
     DB::dontRequireField('Post', 'IsGlobalSticky');
//.........这里部分代码省略.........
开发者ID:RyeDesigns,项目名称:silverstripe-forum,代码行数:101,代码来源:ForumMigrationTask.php

示例2: requireDefaultRecords

 /**
  * Add default records to database
  *
  * This function is called whenever the database is built, after the
  * database tables have all been created.
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $code = "ACCESS_FORUM";
     if (!($forumGroup = DataObject::get_one("Group", "\"Group\".\"Code\" = 'forum-members'"))) {
         $group = new Group();
         $group->Code = 'forum-members';
         $group->Title = "Forum Members";
         $group->write();
         Permission::grant($group->ID, $code);
         DB::alteration_message(_t('Forum.GROUPCREATED', 'Forum Members group created'), "created");
     } else {
         if (DB::query("SELECT * FROM \"Permission\" WHERE \"GroupID\" = '{$forumGroup->ID}' AND \"Code\" LIKE '{$code}'")->numRecords() == 0) {
             Permission::grant($forumGroup->ID, $code);
         }
     }
     if (!($category = DataObject::get_one("ForumCategory"))) {
         $category = new ForumCategory();
         $category->Title = _t('Forum.DEFAULTCATEGORY', 'General');
         $category->write();
     }
     if (!DataObject::get_one("ForumHolder")) {
         $forumholder = new ForumHolder();
         $forumholder->Title = "Forums";
         $forumholder->URLSegment = "forums";
         $forumholder->Content = "<p>" . _t('Forum.WELCOMEFORUMHOLDER', 'Welcome to SilverStripe Forum Module! This is the default ForumHolder page. You can now add forums.') . "</p>";
         $forumholder->Status = "Published";
         $forumholder->write();
         $forumholder->publish("Stage", "Live");
         DB::alteration_message(_t('Forum.FORUMHOLDERCREATED', 'ForumHolder page created'), "created");
         $forum = new Forum();
         $forum->Title = _t('Forum.TITLE', 'General Discussion');
         $forum->URLSegment = "general-discussion";
         $forum->ParentID = $forumholder->ID;
         $forum->Content = "<p>" . _t('Forum.WELCOMEFORUM', 'Welcome to SilverStripe Forum Module! This is the default Forum page. You can now add topics.') . "</p>";
         $forum->Status = "Published";
         $forum->CategoryID = $category->ID;
         $forum->write();
         $forum->publish("Stage", "Live");
         DB::alteration_message(_t('Forum.FORUMCREATED', 'Forum page created'), "created");
     }
 }
开发者ID:nicmart,项目名称:comperio-site,代码行数:48,代码来源:Forum.php

示例3: requireDefaultRecords

 /**
  * Add default records to database
  *
  * This function is called whenever the database is built, after the
  * database tables have all been created.
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $code = "ACCESS_FORUM";
     if (!($forumGroup = Group::get()->filter('Code', 'forum-members')->first())) {
         $group = new Group();
         $group->Code = 'forum-members';
         $group->Title = "Forum Members";
         $group->write();
         Permission::grant($group->ID, $code);
         DB::alteration_message(_t('Forum.GROUPCREATED', 'Forum Members group created'), 'created');
     } else {
         if (!Permission::get()->filter(array('GroupID' => $forumGroup->ID, 'Code' => $code))->exists()) {
             Permission::grant($forumGroup->ID, $code);
         }
     }
     if (!($category = ForumCategory::get()->first())) {
         $category = new ForumCategory();
         $category->Title = _t('Forum.DEFAULTCATEGORY', 'General');
         $category->write();
     }
     if (!ForumHolder::get()->exists()) {
         $forumholder = new ForumHolder();
         $forumholder->Title = "Forums";
         $forumholder->URLSegment = "forums";
         $forumholder->Content = "<p>" . _t('Forum.WELCOMEFORUMHOLDER', 'Welcome to SilverStripe Forum Module! This is the default ForumHolder page. You can now add forums.') . "</p>";
         $forumholder->Status = "Published";
         $forumholder->write();
         $forumholder->publish("Stage", "Live");
         DB::alteration_message(_t('Forum.FORUMHOLDERCREATED', 'ForumHolder page created'), "created");
         $forum = new Forum();
         $forum->Title = _t('Forum.TITLE', 'General Discussion');
         $forum->URLSegment = "general-discussion";
         $forum->ParentID = $forumholder->ID;
         $forum->Content = "<p>" . _t('Forum.WELCOMEFORUM', 'Welcome to SilverStripe Forum Module! This is the default Forum page. You can now add topics.') . "</p>";
         $forum->Status = "Published";
         $forum->CategoryID = $category->ID;
         $forum->write();
         $forum->publish("Stage", "Live");
         DB::alteration_message(_t('Forum.FORUMCREATED', 'Forum page created'), "created");
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-forum,代码行数:48,代码来源:Forum.php


注:本文中的Forum::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。