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


PHP PhrictionDocument::getProjectSlugIdentifier方法代码示例

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


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

示例1: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $slug = PhabricatorSlug::normalize($request->getStr('slug'));
     if ($request->isFormPost()) {
         $document = id(new PhrictionDocumentQuery())->setViewer($user)->withSlugs(array($slug))->executeOne();
         $prompt = $request->getStr('prompt', 'no');
         $document_exists = $document && $document->getStatus() == PhrictionDocumentStatus::STATUS_EXISTS;
         if ($document_exists && $prompt == 'no') {
             $dialog = new AphrontDialogView();
             $dialog->setSubmitURI('/phriction/new/')->setTitle(pht('Edit Existing Document?'))->setUser($user)->appendChild(pht('The document %s already exists. Do you want to edit it instead?', phutil_tag('tt', array(), $slug)))->addHiddenInput('slug', $slug)->addHiddenInput('prompt', 'yes')->addCancelButton('/w/')->addSubmitButton(pht('Edit Document'));
             return id(new AphrontDialogResponse())->setDialog($dialog);
         } else {
             if (PhrictionDocument::isProjectSlug($slug)) {
                 $project = id(new PhabricatorProjectQuery())->setViewer($user)->withPhrictionSlugs(array(PhrictionDocument::getProjectSlugIdentifier($slug)))->executeOne();
                 if (!$project) {
                     $dialog = new AphrontDialogView();
                     $dialog->setSubmitURI('/w/')->setTitle(pht('Oops!'))->setUser($user)->appendChild(pht('You cannot create wiki pages under "projects/",
               because they are reserved as project pages.
               Create a new project with this name first.'))->addCancelButton('/w/', 'Okay');
                     return id(new AphrontDialogResponse())->setDialog($dialog);
                 }
             }
         }
         $uri = '/phriction/edit/?slug=' . $slug;
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     if ($slug == '/') {
         $slug = '';
     }
     $view = id(new PHUIFormLayoutView())->appendChild(id(new AphrontFormTextControl())->setLabel('/w/')->setValue($slug)->setName('slug'));
     $dialog = id(new AphrontDialogView())->setUser($user)->setTitle(pht('New Document'))->setSubmitURI('/phriction/new/')->appendChild(phutil_tag('p', array(), pht('Create a new document at')))->appendChild($view)->addSubmitButton(pht('Create'))->addCancelButton('/w/');
     return id(new AphrontDialogResponse())->setDialog($dialog);
 }
开发者ID:denghp,项目名称:phabricator,代码行数:35,代码来源:PhrictionNewController.php

示例2: testProjectSlugIdentifiers

 public function testProjectSlugIdentifiers()
 {
     $slugs = array('projects/' => null, 'derp/' => null, 'projects/a/' => 'a/', 'projects/a/b/' => 'a/');
     foreach ($slugs as $slug => $expect) {
         $ex = null;
         $result = null;
         try {
             $result = PhrictionDocument::getProjectSlugIdentifier($slug);
         } catch (Exception $e) {
             $ex = $e;
         }
         if ($expect === null) {
             $this->assertEqual(true, (bool) $ex, "Slug '{$slug}' is invalid.");
         } else {
             $this->assertEqual($expect, $result, "Slug '{$slug}' identifier.");
         }
     }
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:18,代码来源:PhrictionDocumentTestCase.php

示例3: willFilterPage

 protected function willFilterPage(array $documents)
 {
     // To view a Phriction document, you must also be able to view all of the
     // ancestor documents. Filter out documents which have ancestors that are
     // not visible.
     $document_map = array();
     foreach ($documents as $document) {
         $document_map[$document->getSlug()] = $document;
         foreach ($document->getAncestors() as $key => $ancestor) {
             if ($ancestor) {
                 $document_map[$key] = $ancestor;
             }
         }
     }
     $filtered_map = $this->applyPolicyFilter($document_map, array(PhabricatorPolicyCapability::CAN_VIEW));
     // Filter all of the documents where a parent is not visible.
     foreach ($documents as $document_key => $document) {
         // If the document itself is not visible, filter it.
         if (!isset($filtered_map[$document->getSlug()])) {
             $this->didRejectResult($documents[$document_key]);
             unset($documents[$document_key]);
             continue;
         }
         // If an ancestor exists but is not visible, filter the document.
         foreach ($document->getAncestors() as $ancestor_key => $ancestor) {
             if (!$ancestor) {
                 continue;
             }
             if (!isset($filtered_map[$ancestor_key])) {
                 $this->didRejectResult($documents[$document_key]);
                 unset($documents[$document_key]);
                 break;
             }
         }
     }
     if (!$documents) {
         return $documents;
     }
     if ($this->needContent) {
         $contents = id(new PhrictionContent())->loadAllWhere('id IN (%Ld)', mpull($documents, 'getContentID'));
         foreach ($documents as $key => $document) {
             $content_id = $document->getContentID();
             if (empty($contents[$content_id])) {
                 unset($documents[$key]);
                 continue;
             }
             $document->attachContent($contents[$content_id]);
         }
     }
     foreach ($documents as $document) {
         $document->attachProject(null);
     }
     $project_slugs = array();
     foreach ($documents as $key => $document) {
         $slug = $document->getSlug();
         if (!PhrictionDocument::isProjectSlug($slug)) {
             continue;
         }
         $project_slugs[$key] = PhrictionDocument::getProjectSlugIdentifier($slug);
     }
     if ($project_slugs) {
         $projects = id(new PhabricatorProjectQuery())->setViewer($this->getViewer())->withPhrictionSlugs($project_slugs)->execute();
         $projects = mpull($projects, null, 'getPhrictionSlug');
         foreach ($documents as $key => $document) {
             $slug = idx($project_slugs, $key);
             if ($slug) {
                 $project = idx($projects, $slug);
                 if (!$project) {
                     unset($documents[$key]);
                     continue;
                 }
                 $document->attachProject($project);
             }
         }
     }
     return $documents;
 }
开发者ID:denghp,项目名称:phabricator,代码行数:77,代码来源:PhrictionDocumentQuery.php

示例4: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $slug = PhrictionDocument::normalizeSlug($this->slug);
     if ($slug != $this->slug) {
         $uri = PhrictionDocument::getSlugURI($slug);
         // Canonicalize pages to their one true URI.
         return id(new AphrontRedirectResponse())->setURI($uri);
     }
     require_celerity_resource('phriction-document-css');
     $document = id(new PhrictionDocument())->loadOneWhere('slug = %s', $slug);
     $breadcrumbs = $this->renderBreadcrumbs($slug);
     $version_note = null;
     if (!$document) {
         $create_uri = '/phriction/edit/?slug=' . $slug;
         $page_content = '<div class="phriction-content">' . '<em>No content here!</em><br />' . 'No document found at <tt>' . phutil_escape_html($slug) . '</tt>. ' . 'You can <strong>' . phutil_render_tag('a', array('href' => $create_uri), 'create a new document') . '</strong>.' . '</div>';
         $page_title = 'Page Not Found';
         $button = phutil_render_tag('a', array('href' => $create_uri, 'class' => 'green button'), 'Create Page');
         $buttons = $button;
     } else {
         $version = $request->getInt('v');
         if ($version) {
             $content = id(new PhrictionContent())->loadOneWhere('documentID = %d AND version = %d', $document->getID(), $version);
             if (!$content) {
                 return new Aphront404Response();
             }
             if ($content->getID() != $document->getContentID()) {
                 $version_note = new AphrontErrorView();
                 $version_note->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
                 $version_note->setTitle('Older Version');
                 $version_note->appendChild('You are viewing an older version of this document, as it ' . 'appeared on ' . phabricator_datetime($content->getDateCreated(), $user) . '.');
             }
         } else {
             $content = id(new PhrictionContent())->load($document->getContentID());
         }
         $page_title = $content->getTitle();
         $project_phid = null;
         if (PhrictionDocument::isProjectSlug($slug)) {
             $project = id(new PhabricatorProject())->loadOneWhere('phrictionSlug = %s', PhrictionDocument::getProjectSlugIdentifier($slug));
             $project_phid = $project->getPHID();
         }
         $phids = array_filter(array($content->getAuthorPHID(), $project_phid));
         $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
         $age = time() - $content->getDateCreated();
         $age = floor($age / (60 * 60 * 24));
         if ($age < 1) {
             $when = 'today';
         } else {
             if ($age == 1) {
                 $when = 'yesterday';
             } else {
                 $when = "{$age} days ago";
             }
         }
         $project_info = null;
         if ($project_phid) {
             $project_info = '<br />This document is about the project ' . $handles[$project_phid]->renderLink() . '.';
         }
         $byline = '<div class="phriction-byline">' . "Last updated {$when} by " . $handles[$content->getAuthorPHID()]->renderLink() . '.' . $project_info . '</div>';
         $doc_status = $document->getStatus();
         if ($doc_status == PhrictionDocumentStatus::STATUS_EXISTS) {
             $core_content = $content->renderContent();
         } else {
             if ($doc_status == PhrictionDocumentStatus::STATUS_DELETED) {
                 $notice = new AphrontErrorView();
                 $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
                 $notice->setTitle('Document Deleted');
                 $notice->appendChild('This document has been deleted. You can edit it to put new content ' . 'here, or use history to revert to an earlier version.');
                 $core_content = $notice->render();
             } else {
                 throw new Exception("Unknown document status '{$doc_status}'!");
             }
         }
         $page_content = '<div class="phriction-content">' . $byline . $core_content . '</div>';
         $edit_button = phutil_render_tag('a', array('href' => '/phriction/edit/' . $document->getID() . '/', 'class' => 'button'), 'Edit Document');
         $history_button = phutil_render_tag('a', array('href' => PhrictionDocument::getSlugURI($slug, 'history'), 'class' => 'button grey'), 'View History');
         // these float right so history_button which is right most goes first
         $buttons = $history_button . $edit_button;
     }
     if ($version_note) {
         $version_note = $version_note->render();
     }
     $children = $this->renderChildren($slug);
     $page = '<div class="phriction-header">' . $buttons . '<h1>' . phutil_escape_html($page_title) . '</h1>' . $breadcrumbs . '</div>' . $version_note . $page_content . $children;
     return $this->buildStandardPageResponse($page, array('title' => 'Phriction - ' . $page_title));
 }
开发者ID:netcomtec,项目名称:phabricator,代码行数:87,代码来源:PhrictionDocumentController.php

示例5: buildPropertyListView

 private function buildPropertyListView(PhrictionDocument $document, PhrictionContent $content, $slug)
 {
     $viewer = $this->getRequest()->getUser();
     $view = id(new PHUIPropertyListView())->setUser($viewer)->setObject($document);
     $project_phid = null;
     if (PhrictionDocument::isProjectSlug($slug)) {
         $project = id(new PhabricatorProjectQuery())->setViewer($viewer)->withPhrictionSlugs(array(PhrictionDocument::getProjectSlugIdentifier($slug)))->executeOne();
         if ($project) {
             $project_phid = $project->getPHID();
         }
     }
     $phids = array_filter(array($content->getAuthorPHID(), $project_phid));
     $this->loadHandles($phids);
     $project_info = null;
     if ($project_phid) {
         $view->addProperty(pht('Project Info'), $this->getHandle($project_phid)->renderLink());
     }
     $view->addProperty(pht('Last Author'), $this->getHandle($content->getAuthorPHID())->renderLink());
     $age = time() - $content->getDateCreated();
     $age = floor($age / (60 * 60 * 24));
     if ($age < 1) {
         $when = pht('Today');
     } else {
         if ($age == 1) {
             $when = pht('Yesterday');
         } else {
             $when = pht('%d Days Ago', $age);
         }
     }
     $view->addProperty(pht('Last Updated'), $when);
     return $view;
 }
开发者ID:denghp,项目名称:phabricator,代码行数:32,代码来源:PhrictionDocumentController.php

示例6: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($this->id) {
         $document = id(new PhrictionDocument())->load($this->id);
         if (!$document) {
             return new Aphront404Response();
         }
         $revert = $request->getInt('revert');
         if ($revert) {
             $content = id(new PhrictionContent())->loadOneWhere('documentID = %d AND version = %d', $document->getID(), $revert);
             if (!$content) {
                 return new Aphront404Response();
             }
         } else {
             $content = id(new PhrictionContent())->load($document->getContentID());
         }
     } else {
         $slug = $request->getStr('slug');
         $slug = PhabricatorSlug::normalize($slug);
         if (!$slug) {
             return new Aphront404Response();
         }
         $document = id(new PhrictionDocument())->loadOneWhere('slug = %s', $slug);
         if ($document) {
             $content = id(new PhrictionContent())->load($document->getContentID());
         } else {
             if (PhrictionDocument::isProjectSlug($slug)) {
                 $project = id(new PhabricatorProject())->loadOneWhere('phrictionSlug = %s', PhrictionDocument::getProjectSlugIdentifier($slug));
                 if (!$project) {
                     return new Aphront404Response();
                 }
             }
             $document = new PhrictionDocument();
             $document->setSlug($slug);
             $content = new PhrictionContent();
             $content->setSlug($slug);
             $default_title = PhabricatorSlug::getDefaultTitle($slug);
             $content->setTitle($default_title);
         }
     }
     if ($request->getBool('nodraft')) {
         $draft = null;
         $draft_key = null;
     } else {
         if ($document->getPHID()) {
             $draft_key = $document->getPHID() . ':' . $content->getVersion();
         } else {
             $draft_key = 'phriction:' . $content->getSlug();
         }
         $draft = id(new PhabricatorDraft())->loadOneWhere('authorPHID = %s AND draftKey = %s', $user->getPHID(), $draft_key);
     }
     require_celerity_resource('phriction-document-css');
     $e_title = true;
     $notes = null;
     $errors = array();
     if ($request->isFormPost()) {
         $title = $request->getStr('title');
         $notes = $request->getStr('description');
         if (!strlen($title)) {
             $e_title = 'Required';
             $errors[] = 'Document title is required.';
         } else {
             $e_title = null;
         }
         if ($document->getID()) {
             if ($content->getTitle() == $title && $content->getContent() == $request->getStr('content')) {
                 $dialog = new AphrontDialogView();
                 $dialog->setUser($user);
                 $dialog->setTitle('No Edits');
                 $dialog->appendChild('<p>You did not make any changes to the document.</p>');
                 $dialog->addCancelButton($request->getRequestURI());
                 return id(new AphrontDialogResponse())->setDialog($dialog);
             }
         }
         if (!count($errors)) {
             $editor = id(PhrictionDocumentEditor::newForSlug($document->getSlug()))->setUser($user)->setTitle($title)->setContent($request->getStr('content'))->setDescription($notes);
             $editor->save();
             if ($draft) {
                 $draft->delete();
             }
             $uri = PhrictionDocument::getSlugURI($document->getSlug());
             return id(new AphrontRedirectResponse())->setURI($uri);
         }
     }
     $error_view = null;
     if ($errors) {
         $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors);
     }
     if ($document->getID()) {
         $panel_header = 'Edit Phriction Document';
         $submit_button = 'Save Changes';
         $delete_button = phutil_render_tag('a', array('href' => '/phriction/delete/' . $document->getID() . '/', 'class' => 'grey button'), 'Delete Document');
     } else {
         $panel_header = 'Create New Phriction Document';
         $submit_button = 'Create Document';
         $delete_button = null;
     }
     $uri = $document->getSlug();
//.........这里部分代码省略.........
开发者ID:rudimk,项目名称:phabricator,代码行数:101,代码来源:PhrictionEditController.php

示例7: processRequest

 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $current_version = null;
     if ($this->id) {
         $document = id(new PhrictionDocumentQuery())->setViewer($user)->withIDs(array($this->id))->needContent(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
         if (!$document) {
             return new Aphront404Response();
         }
         $current_version = $document->getContent()->getVersion();
         $revert = $request->getInt('revert');
         if ($revert) {
             $content = id(new PhrictionContent())->loadOneWhere('documentID = %d AND version = %d', $document->getID(), $revert);
             if (!$content) {
                 return new Aphront404Response();
             }
         } else {
             $content = $document->getContent();
         }
     } else {
         $slug = $request->getStr('slug');
         $slug = PhabricatorSlug::normalize($slug);
         if (!$slug) {
             return new Aphront404Response();
         }
         $document = id(new PhrictionDocumentQuery())->setViewer($user)->withSlugs(array($slug))->needContent(true)->executeOne();
         if ($document) {
             $content = $document->getContent();
             $current_version = $content->getVersion();
         } else {
             if (PhrictionDocument::isProjectSlug($slug)) {
                 $project = id(new PhabricatorProjectQuery())->setViewer($user)->withPhrictionSlugs(array(PhrictionDocument::getProjectSlugIdentifier($slug)))->executeOne();
                 if (!$project) {
                     return new Aphront404Response();
                 }
             }
             $document = new PhrictionDocument();
             $document->setSlug($slug);
             $content = new PhrictionContent();
             $content->setSlug($slug);
             $default_title = PhabricatorSlug::getDefaultTitle($slug);
             $content->setTitle($default_title);
         }
     }
     if ($request->getBool('nodraft')) {
         $draft = null;
         $draft_key = null;
     } else {
         if ($document->getPHID()) {
             $draft_key = $document->getPHID() . ':' . $content->getVersion();
         } else {
             $draft_key = 'phriction:' . $content->getSlug();
         }
         $draft = id(new PhabricatorDraft())->loadOneWhere('authorPHID = %s AND draftKey = %s', $user->getPHID(), $draft_key);
     }
     require_celerity_resource('phriction-document-css');
     $e_title = true;
     $notes = null;
     $errors = array();
     if ($request->isFormPost()) {
         $overwrite = $request->getBool('overwrite');
         if (!$overwrite) {
             $edit_version = $request->getStr('contentVersion');
             if ($edit_version != $current_version) {
                 $dialog = $this->newDialog()->setTitle(pht('Edit Conflict!'))->appendParagraph(pht('Another user made changes to this document after you began ' . 'editing it. Do you want to overwrite their changes?'))->appendParagraph(pht('If you choose to overwrite their changes, you should review ' . 'the document edit history to see what you overwrote, and ' . 'then make another edit to merge the changes if necessary.'))->addSubmitButton(pht('Overwrite Changes'))->addCancelButton($request->getRequestURI());
                 $dialog->addHiddenInput('overwrite', 'true');
                 foreach ($request->getPassthroughRequestData() as $key => $value) {
                     $dialog->addHiddenInput($key, $value);
                 }
                 return $dialog;
             }
         }
         $title = $request->getStr('title');
         $notes = $request->getStr('description');
         if (!strlen($title)) {
             $e_title = pht('Required');
             $errors[] = pht('Document title is required.');
         } else {
             $e_title = null;
         }
         if ($document->getID()) {
             if ($content->getTitle() == $title && $content->getContent() == $request->getStr('content')) {
                 $dialog = new AphrontDialogView();
                 $dialog->setUser($user);
                 $dialog->setTitle(pht('No Edits'));
                 $dialog->appendChild(phutil_tag('p', array(), pht('You did not make any changes to the document.')));
                 $dialog->addCancelButton($request->getRequestURI());
                 return id(new AphrontDialogResponse())->setDialog($dialog);
             }
         } else {
             if (!strlen($request->getStr('content'))) {
                 // We trigger this only for new pages. For existing pages, deleting
                 // all the content counts as deleting the page.
                 $dialog = new AphrontDialogView();
                 $dialog->setUser($user);
                 $dialog->setTitle(pht('Empty Page'));
                 $dialog->appendChild(phutil_tag('p', array(), pht('You can not create an empty document.')));
                 $dialog->addCancelButton($request->getRequestURI());
                 return id(new AphrontDialogResponse())->setDialog($dialog);
//.........这里部分代码省略.........
开发者ID:denghp,项目名称:phabricator,代码行数:101,代码来源:PhrictionEditController.php

示例8: updateDocument

 private function updateDocument($document, $content, $new_content)
 {
     $is_new = false;
     if (!$document->getID()) {
         $is_new = true;
     }
     $new_content->setVersion($content->getVersion() + 1);
     $change_type = $new_content->getChangeType();
     switch ($change_type) {
         case PhrictionChangeType::CHANGE_EDIT:
             $doc_status = PhrictionDocumentStatus::STATUS_EXISTS;
             $feed_action = $is_new ? PhrictionActionConstants::ACTION_CREATE : PhrictionActionConstants::ACTION_EDIT;
             break;
         case PhrictionChangeType::CHANGE_DELETE:
             $doc_status = PhrictionDocumentStatus::STATUS_DELETED;
             $feed_action = PhrictionActionConstants::ACTION_DELETE;
             if ($is_new) {
                 throw new Exception("You can not delete a document which doesn't exist yet!");
             }
             break;
         default:
             throw new Exception("Unsupported content change type '{$change_type}'!");
     }
     $document->setStatus($doc_status);
     // TODO: This should be transactional.
     if ($is_new) {
         $document->save();
     }
     $new_content->setDocumentID($document->getID());
     $new_content->save();
     $document->setContentID($new_content->getID());
     $document->save();
     $document->attachContent($new_content);
     PhabricatorSearchPhrictionIndexer::indexDocument($document);
     $project_phid = null;
     $slug = $document->getSlug();
     if (PhrictionDocument::isProjectSlug($slug)) {
         $project = id(new PhabricatorProject())->loadOneWhere('phrictionSlug = %s', PhrictionDocument::getProjectSlugIdentifier($slug));
         if ($project) {
             $project_phid = $project->getPHID();
         }
     }
     $related_phids = array($document->getPHID(), $this->user->getPHID());
     if ($project_phid) {
         $related_phids[] = $project_phid;
     }
     id(new PhabricatorFeedStoryPublisher())->setRelatedPHIDs($related_phids)->setStoryAuthorPHID($this->user->getPHID())->setStoryTime(time())->setStoryType(PhabricatorFeedStoryTypeConstants::STORY_PHRICTION)->setStoryData(array('phid' => $document->getPHID(), 'action' => $feed_action, 'content' => phutil_utf8_shorten($new_content->getContent(), 140), 'project' => $project_phid))->publish();
     return $this;
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:49,代码来源:PhrictionDocumentEditor.php

示例9: updateDocument

 private function updateDocument($document, $content, $new_content)
 {
     $is_new = false;
     if (!$document->getID()) {
         $is_new = true;
     }
     $new_content->setVersion($content->getVersion() + 1);
     $change_type = $new_content->getChangeType();
     switch ($change_type) {
         case PhrictionChangeType::CHANGE_EDIT:
             $doc_status = PhrictionDocumentStatus::STATUS_EXISTS;
             $feed_action = $is_new ? PhrictionActionConstants::ACTION_CREATE : PhrictionActionConstants::ACTION_EDIT;
             break;
         case PhrictionChangeType::CHANGE_DELETE:
             $doc_status = PhrictionDocumentStatus::STATUS_DELETED;
             $feed_action = PhrictionActionConstants::ACTION_DELETE;
             if ($is_new) {
                 throw new Exception("You can not delete a document which doesn't exist yet!");
             }
             break;
         case PhrictionChangeType::CHANGE_STUB:
             $doc_status = PhrictionDocumentStatus::STATUS_STUB;
             $feed_action = null;
             break;
         case PhrictionChangeType::CHANGE_MOVE_AWAY:
             $doc_status = PhrictionDocumentStatus::STATUS_MOVED;
             $feed_action = null;
             break;
         case PhrictionChangeType::CHANGE_MOVE_HERE:
             $doc_status = PhrictionDocumentStatus::STATUS_EXISTS;
             $feed_action = PhrictionActionConstants::ACTION_MOVE_HERE;
             break;
         default:
             throw new Exception("Unsupported content change type '{$change_type}'!");
     }
     $document->setStatus($doc_status);
     // TODO: This should be transactional.
     if ($is_new) {
         $document->save();
     }
     $new_content->setDocumentID($document->getID());
     $new_content->save();
     $document->setContentID($new_content->getID());
     $document->save();
     $document->attachContent($new_content);
     id(new PhabricatorSearchIndexer())->queueDocumentForIndexing($document->getPHID());
     // Stub out empty parent documents if they don't exist
     $ancestral_slugs = PhabricatorSlug::getAncestry($document->getSlug());
     if ($ancestral_slugs) {
         $ancestors = id(new PhrictionDocument())->loadAllWhere('slug IN (%Ls)', $ancestral_slugs);
         $ancestors = mpull($ancestors, null, 'getSlug');
         foreach ($ancestral_slugs as $slug) {
             // We check for change type to prevent near-infinite recursion
             if (!isset($ancestors[$slug]) && $new_content->getChangeType() != PhrictionChangeType::CHANGE_STUB) {
                 id(PhrictionDocumentEditor::newForSlug($slug))->setActor($this->getActor())->setTitle(PhabricatorSlug::getDefaultTitle($slug))->setContent('')->setDescription(pht('Empty Parent Document'))->stub();
             }
         }
     }
     $project_phid = null;
     $slug = $document->getSlug();
     if (PhrictionDocument::isProjectSlug($slug)) {
         $project = id(new PhabricatorProjectQuery())->setViewer($this->requireActor())->withPhrictionSlugs(array(PhrictionDocument::getProjectSlugIdentifier($slug)))->executeOne();
         if ($project) {
             $project_phid = $project->getPHID();
         }
     }
     $related_phids = array($document->getPHID(), $this->getActor()->getPHID());
     if ($project_phid) {
         $related_phids[] = $project_phid;
     }
     if ($this->fromDocumentPHID) {
         $related_phids[] = $this->fromDocumentPHID;
     }
     if ($feed_action) {
         $content_str = id(new PhutilUTF8StringTruncator())->setMaximumGlyphs(140)->truncateString($new_content->getContent());
         id(new PhabricatorFeedStoryPublisher())->setRelatedPHIDs($related_phids)->setStoryAuthorPHID($this->getActor()->getPHID())->setStoryTime(time())->setStoryType(PhabricatorFeedStoryTypeConstants::STORY_PHRICTION)->setStoryData(array('phid' => $document->getPHID(), 'action' => $feed_action, 'content' => $content_str, 'project' => $project_phid, 'movedFromPHID' => $this->fromDocumentPHID))->publish();
     }
     // TODO: Migrate to ApplicationTransactions fast, so we get rid of this code
     $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($document->getPHID());
     $this->sendMailToSubscribers($subscribers, $content);
     return $this;
 }
开发者ID:denghp,项目名称:phabricator,代码行数:82,代码来源:PhrictionDocumentEditor.php


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