Projects - tighten up a few things
Summary: Fixes T2675, T2676. - when the last person leaves a project it is archived. - a script to archive all memberless projects - better feed stories for the various policy edits you can do - phriction pages are also moved as you rename projects Test Plan: edited some projects and noted reasonable feed stories. ran script against test data and it worked! left a last man standing project and it archived. renamed a project to "a" then "b" then "a" (etc) and it worked including phrictiondocument moves Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2676, T2675 Differential Revision: https://secure.phabricator.com/D6478
This commit is contained in:
		
							
								
								
									
										39
									
								
								resources/sql/patches/20130716.archivememberlessprojects.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								resources/sql/patches/20130716.archivememberlessprojects.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | echo "Archiving projects with no members...\n"; | ||||||
|  |  | ||||||
|  | $table = new PhabricatorProject(); | ||||||
|  | $table->openTransaction(); | ||||||
|  |  | ||||||
|  | foreach (new LiskMigrationIterator($table) as $project) { | ||||||
|  |  | ||||||
|  |   $members = PhabricatorEdgeQuery::loadDestinationPHIDs( | ||||||
|  |     $project->getPHID(), | ||||||
|  |     PhabricatorEdgeConfig::TYPE_PROJ_MEMBER); | ||||||
|  |  | ||||||
|  |   if (count($members)) { | ||||||
|  |     echo sprintf( | ||||||
|  |       'Project "%s" has %d members; skipping.', | ||||||
|  |       $project->getName(), | ||||||
|  |       count($members)), "\n"; | ||||||
|  |     continue; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   if ($project->getStatus() == PhabricatorProjectStatus::STATUS_ARCHIVED) { | ||||||
|  |     echo sprintf( | ||||||
|  |       'Project "%s" already archived; skipping.', | ||||||
|  |       $project->getName()), "\n"; | ||||||
|  |     continue; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   echo sprintf('Archiving project "%s"...', $project->getName()), "\n"; | ||||||
|  |   queryfx( | ||||||
|  |     $table->establishConnection('w'), | ||||||
|  |     'UPDATE %T SET status = %s WHERE id = %d', | ||||||
|  |     $table->getTableName(), | ||||||
|  |     PhabricatorProjectStatus::STATUS_ARCHIVED, | ||||||
|  |     $project->getID()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | $table->saveTransaction(); | ||||||
|  | echo "\nDone.\n"; | ||||||
| @@ -86,6 +86,21 @@ final class PhabricatorFeedStoryProject extends PhabricatorFeedStory { | |||||||
|             $this->renderHandleList($rem)); |             $this->renderHandleList($rem)); | ||||||
|         } |         } | ||||||
|         break; |         break; | ||||||
|  |       case PhabricatorProjectTransactionType::TYPE_CAN_VIEW: | ||||||
|  |         $action = hsprintf( | ||||||
|  |           'changed the visibility for %s.', | ||||||
|  |           $this->linkTo($proj_phid)); | ||||||
|  |         break; | ||||||
|  |       case PhabricatorProjectTransactionType::TYPE_CAN_EDIT: | ||||||
|  |         $action = hsprintf( | ||||||
|  |           'changed the edit policy for %s.', | ||||||
|  |           $this->linkTo($proj_phid)); | ||||||
|  |         break; | ||||||
|  |       case PhabricatorProjectTransactionType::TYPE_CAN_JOIN: | ||||||
|  |         $action = hsprintf( | ||||||
|  |           'changed the join policy for %s.', | ||||||
|  |           $this->linkTo($proj_phid)); | ||||||
|  |         break; | ||||||
|       default: |       default: | ||||||
|         $action = hsprintf('updated project %s.', $this->linkTo($proj_phid)); |         $action = hsprintf('updated project %s.', $this->linkTo($proj_phid)); | ||||||
|         break; |         break; | ||||||
|   | |||||||
| @@ -8,6 +8,16 @@ final class PhabricatorProjectEditor extends PhabricatorEditor { | |||||||
|   private $addEdges = array(); |   private $addEdges = array(); | ||||||
|   private $remEdges = array(); |   private $remEdges = array(); | ||||||
|  |  | ||||||
|  |   private $shouldArchive = false; | ||||||
|  |  | ||||||
|  |   private function setShouldArchive($should_archive) { | ||||||
|  |     $this->shouldArchive = $should_archive; | ||||||
|  |     return $this; | ||||||
|  |   } | ||||||
|  |   private function shouldArchive() { | ||||||
|  |     return $this->shouldArchive; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   public static function applyJoinProject( |   public static function applyJoinProject( | ||||||
|     PhabricatorProject $project, |     PhabricatorProject $project, | ||||||
|     PhabricatorUser $user) { |     PhabricatorUser $user) { | ||||||
| @@ -120,6 +130,10 @@ final class PhabricatorProjectEditor extends PhabricatorEditor { | |||||||
|  |  | ||||||
|     try { |     try { | ||||||
|       $project->openTransaction(); |       $project->openTransaction(); | ||||||
|  |  | ||||||
|  |         if ($this->shouldArchive()) { | ||||||
|  |           $project->setStatus(PhabricatorProjectStatus::STATUS_ARCHIVED); | ||||||
|  |         } | ||||||
|         $project->save(); |         $project->save(); | ||||||
|  |  | ||||||
|         $edge_type = PhabricatorEdgeConfig::TYPE_PROJ_MEMBER; |         $edge_type = PhabricatorEdgeConfig::TYPE_PROJ_MEMBER; | ||||||
| @@ -152,9 +166,6 @@ final class PhabricatorProjectEditor extends PhabricatorEditor { | |||||||
|       throw $ex; |       throw $ex; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // TODO: If we rename a project, we should move its Phriction page. Do |  | ||||||
|     // that once Phriction supports document moves. |  | ||||||
|  |  | ||||||
|     return $this; |     return $this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -233,8 +244,37 @@ final class PhabricatorProjectEditor extends PhabricatorEditor { | |||||||
|     $type = $xaction->getTransactionType(); |     $type = $xaction->getTransactionType(); | ||||||
|     switch ($type) { |     switch ($type) { | ||||||
|       case PhabricatorProjectTransactionType::TYPE_NAME: |       case PhabricatorProjectTransactionType::TYPE_NAME: | ||||||
|  |         $old_slug = $project->getFullPhrictionSlug(); | ||||||
|         $project->setName($xaction->getNewValue()); |         $project->setName($xaction->getNewValue()); | ||||||
|         $project->setPhrictionSlug($xaction->getNewValue()); |         $project->setPhrictionSlug($xaction->getNewValue()); | ||||||
|  |  | ||||||
|  |         if ($xaction->getOldValue()) { | ||||||
|  |           $old_document = id(new PhrictionDocument()) | ||||||
|  |             ->loadOneWhere( | ||||||
|  |               'slug = %s', | ||||||
|  |               $old_slug); | ||||||
|  |           if ($old_document && $old_document->getStatus() == | ||||||
|  |               PhrictionDocumentStatus::STATUS_EXISTS) { | ||||||
|  |             $content = id(new PhrictionContent()) | ||||||
|  |               ->load($old_document->getContentID()); | ||||||
|  |             $from_editor = id(PhrictionDocumentEditor::newForSlug($old_slug)) | ||||||
|  |               ->setActor($this->getActor()) | ||||||
|  |               ->setTitle($content->getTitle()) | ||||||
|  |               ->setContent($content->getContent()) | ||||||
|  |               ->setDescription($content->getDescription()); | ||||||
|  |  | ||||||
|  |             $target_editor = id(PhrictionDocumentEditor::newForSlug( | ||||||
|  |               $project->getFullPhrictionSlug())) | ||||||
|  |               ->setActor($this->getActor()) | ||||||
|  |               ->setTitle($content->getTitle()) | ||||||
|  |               ->setContent($content->getContent()) | ||||||
|  |               ->setDescription($content->getDescription()) | ||||||
|  |               ->moveHere($old_document->getID(), $old_document->getPHID()); | ||||||
|  |  | ||||||
|  |             $target_document = $target_editor->getDocument(); | ||||||
|  |             $from_editor->moveAway($target_document->getID()); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|         $this->validateName($project); |         $this->validateName($project); | ||||||
|         break; |         break; | ||||||
|       case PhabricatorProjectTransactionType::TYPE_STATUS: |       case PhabricatorProjectTransactionType::TYPE_STATUS: | ||||||
| @@ -245,6 +285,9 @@ final class PhabricatorProjectEditor extends PhabricatorEditor { | |||||||
|         $new = array_fill_keys($xaction->getNewValue(), true); |         $new = array_fill_keys($xaction->getNewValue(), true); | ||||||
|         $this->addEdges = array_keys(array_diff_key($new, $old)); |         $this->addEdges = array_keys(array_diff_key($new, $old)); | ||||||
|         $this->remEdges = array_keys(array_diff_key($old, $new)); |         $this->remEdges = array_keys(array_diff_key($old, $new)); | ||||||
|  |         if ($new === array()) { | ||||||
|  |           $this->setShouldArchive(true); | ||||||
|  |         } | ||||||
|         break; |         break; | ||||||
|       case PhabricatorProjectTransactionType::TYPE_CAN_VIEW: |       case PhabricatorProjectTransactionType::TYPE_CAN_VIEW: | ||||||
|         $project->setViewPolicy($xaction->getNewValue()); |         $project->setViewPolicy($xaction->getNewValue()); | ||||||
|   | |||||||
| @@ -128,4 +128,9 @@ final class PhabricatorProject extends PhabricatorProjectDAO | |||||||
|     return $this; |     return $this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   public function getFullPhrictionSlug() { | ||||||
|  |     $slug = $this->getPhrictionSlug(); | ||||||
|  |     return 'projects/'.$slug; | ||||||
|  |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1466,6 +1466,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { | |||||||
|         'type' => 'sql', |         'type' => 'sql', | ||||||
|         'name' => $this->getPatchPath('20130711.pholioimageobsolete2.sql'), |         'name' => $this->getPatchPath('20130711.pholioimageobsolete2.sql'), | ||||||
|       ), |       ), | ||||||
|  |       '20130716.archivememberlessprojects.php' => array( | ||||||
|  |         'type' => 'php', | ||||||
|  |         'name' => $this->getPatchPath('20130716.archivememberlessprojects.php'), | ||||||
|  |       ), | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Bob Trahan
					Bob Trahan