private function materializeProject(PhabricatorProject $project) { if ($project->isMilestone()) { return; } $material_type = PhabricatorProjectMaterializedMemberEdgeType::EDGECONST; $member_type = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST; $project_phid = $project->getPHID(); $descendants = id(new PhabricatorProjectQuery())->setViewer($this->getViewer())->withAncestorProjectPHIDs(array($project->getPHID()))->withIsMilestone(false)->withHasSubprojects(false)->execute(); $descendant_phids = mpull($descendants, 'getPHID'); if ($descendant_phids) { $source_phids = $descendant_phids; $has_subprojects = true; } else { $source_phids = array($project->getPHID()); $has_subprojects = false; } $conn_w = $project->establishConnection('w'); $project->openTransaction(); // Delete any existing materialized member edges. queryfx($conn_w, 'DELETE FROM %T WHERE src = %s AND type = %s', PhabricatorEdgeConfig::TABLE_NAME_EDGE, $project_phid, $material_type); // Copy current member edges to create new materialized edges. queryfx($conn_w, 'INSERT IGNORE INTO %T (src, type, dst, dateCreated, seq) SELECT %s, %d, dst, dateCreated, seq FROM %T WHERE src IN (%Ls) AND type = %d', PhabricatorEdgeConfig::TABLE_NAME_EDGE, $project_phid, $material_type, PhabricatorEdgeConfig::TABLE_NAME_EDGE, $source_phids, $member_type); // Update the hasSubprojects flag. queryfx($conn_w, 'UPDATE %T SET hasSubprojects = %d WHERE id = %d', $project->getTableName(), (int) $has_subprojects, $project->getID()); $project->saveTransaction(); }
<?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";