Page MenuHomestyx hydra

No OneTemporary

diff --git a/resources/sql/patches/079.nametokenindex.php b/resources/sql/patches/079.nametokenindex.php
index b545393693..f8b74ee39d 100644
--- a/resources/sql/patches/079.nametokenindex.php
+++ b/resources/sql/patches/079.nametokenindex.php
@@ -1,14 +1,18 @@
<?php
-$conn = $schema_conn;
-
echo "Indexing username tokens for typeaheads...\n";
-$users = id(new PhabricatorUser())->loadAll();
+$table = new PhabricatorUser();
+$table->openTransaction();
+$table->beginReadLocking();
+
+$users = $table->loadAll();
echo count($users)." users to index";
foreach ($users as $user) {
$user->updateNameTokens();
echo ".";
}
+$table->endReadLocking();
+$table->saveTransaction();
echo "\nDone.\n";
diff --git a/resources/sql/patches/081.filekeys.php b/resources/sql/patches/081.filekeys.php
index 165b24bc61..1a4a3851fe 100644
--- a/resources/sql/patches/081.filekeys.php
+++ b/resources/sql/patches/081.filekeys.php
@@ -1,15 +1,22 @@
<?php
echo "Generating file keys...\n";
-$files = id(new PhabricatorFile())->loadAllWhere('secretKey IS NULL');
+$table = new PhabricatorFile();
+$table->openTransaction();
+$table->beginReadLocking();
+
+$files = $table->loadAllWhere('secretKey IS NULL');
echo count($files).' files to generate keys for';
foreach ($files as $file) {
queryfx(
- $file->establishConnection('r'),
+ $file->establishConnection('w'),
'UPDATE %T SET secretKey = %s WHERE id = %d',
$file->getTableName(),
$file->generateSecretKey(),
$file->getID());
echo '.';
}
+
+$table->endReadLocking();
+$table->saveTransaction();
echo "\nDone.\n";
diff --git a/resources/sql/patches/090.forceuniqueprojectnames.php b/resources/sql/patches/090.forceuniqueprojectnames.php
index 7aa98d22d3..1bd5255886 100644
--- a/resources/sql/patches/090.forceuniqueprojectnames.php
+++ b/resources/sql/patches/090.forceuniqueprojectnames.php
@@ -1,101 +1,107 @@
<?php
echo "Ensuring project names are unique enough...\n";
-$projects = id(new PhabricatorProject())->loadAll();
+$table = new PhabricatorProject();
+$table->openTransaction();
+$table->beginReadLocking();
+
+$projects = $table->loadAll();
$slug_map = array();
foreach ($projects as $project) {
$project->setPhrictionSlug($project->getName());
$slug = $project->getPhrictionSlug();
if ($slug == '/') {
$project_id = $project->getID();
echo "Project #{$project_id} doesn't have a meaningful name...\n";
$project->setName(trim('Unnamed Project '.$project->getName()));
}
$slug_map[$slug][] = $project->getID();
}
foreach ($slug_map as $slug => $similar) {
if (count($similar) <= 1) {
continue;
}
echo "Too many projects are similar to '{$slug}'...\n";
foreach (array_slice($similar, 1, null, true) as $key => $project_id) {
$project = $projects[$project_id];
$old_name = $project->getName();
$new_name = rename_project($project, $projects);
echo "Renaming project #{$project_id} ".
"from '{$old_name}' to '{$new_name}'.\n";
$project->setName($new_name);
}
}
$update = $projects;
while ($update) {
$size = count($update);
foreach ($update as $key => $project) {
$id = $project->getID();
$name = $project->getName();
$project->setPhrictionSlug($name);
$slug = $project->getPhrictionSlug();
echo "Updating project #{$id} '{$name}' ({$slug})...";
try {
queryfx(
$project->establishConnection('w'),
'UPDATE %T SET name = %s, phrictionSlug = %s WHERE id = %d',
$project->getTableName(),
$name,
$slug,
$project->getID());
unset($update[$key]);
echo "okay.\n";
} catch (AphrontQueryDuplicateKeyException $ex) {
echo "failed, will retry.\n";
}
}
if (count($update) == $size) {
throw new Exception(
"Failed to make any progress while updating projects. Schema upgrade ".
"has failed. Go manually fix your project names to be unique (they are ".
"probably ridiculous?) and then try again.");
}
}
+$table->endReadLocking();
+$table->saveTransaction();
echo "Done.\n";
/**
* Rename the project so that it has a unique slug, by appending (2), (3), etc.
* to its name.
*/
function rename_project($project, $projects) {
$suffix = 2;
while (true) {
$new_name = $project->getName().' ('.$suffix.')';
$project->setPhrictionSlug($new_name);
$new_slug = $project->getPhrictionSlug();
$okay = true;
foreach ($projects as $other) {
if ($other->getID() == $project->getID()) {
continue;
}
if ($other->getPhrictionSlug() == $new_slug) {
$okay = false;
break;
}
}
if ($okay) {
break;
} else {
$suffix++;
}
}
return $new_name;
}
diff --git a/resources/sql/patches/093.gitremotes.php b/resources/sql/patches/093.gitremotes.php
index 667fe39d11..7af320bf89 100644
--- a/resources/sql/patches/093.gitremotes.php
+++ b/resources/sql/patches/093.gitremotes.php
@@ -1,42 +1,44 @@
<?php
echo "Stripping remotes from repository default branches...\n";
$table = new PhabricatorRepository();
+$table->openTransaction();
$conn_w = $table->establishConnection('w');
$repos = queryfx_all(
$conn_w,
- 'SELECT id, name, details FROM %T WHERE versionControlSystem = %s',
+ 'SELECT id, name, details FROM %T WHERE versionControlSystem = %s FOR UPDATE',
$table->getTableName(),
'git');
foreach ($repos as $repo) {
$details = json_decode($repo['details'], true);
$old = idx($details, 'default-branch', '');
if (strpos($old, '/') === false) {
continue;
}
$parts = explode('/', $old);
$parts = array_filter($parts);
$new = end($parts);
$details['default-branch'] = $new;
$new_details = json_encode($details);
$id = $repo['id'];
$name = $repo['name'];
echo "Updating default branch for repository #{$id} '{$name}' from ".
"'{$old}' to '{$new}' to remove the explicit remote.\n";
queryfx(
$conn_w,
'UPDATE %T SET details = %s WHERE id = %d',
$table->getTableName(),
$new_details,
$id);
}
+$table->saveTransaction();
echo "Done.\n";
diff --git a/resources/sql/patches/098.heraldruletypemigration.php b/resources/sql/patches/098.heraldruletypemigration.php
index c30d761042..9340455b2e 100644
--- a/resources/sql/patches/098.heraldruletypemigration.php
+++ b/resources/sql/patches/098.heraldruletypemigration.php
@@ -1,46 +1,51 @@
<?php
echo "Checking for rules that can be converted to 'personal'. ";
+$table = new HeraldRule();
+$table->openTransaction();
+$table->beginReadLocking();
-$rules = id(new HeraldRule())->loadAll();
+$rules = $table->loadAll();
foreach ($rules as $rule) {
if ($rule->getRuleType() !== HeraldRuleTypeConfig::RULE_TYPE_PERSONAL) {
$actions = $rule->loadActions();
$can_be_personal = true;
foreach ($actions as $action) {
$target = $action->getTarget();
if (is_array($target)) {
if (count($target) > 1) {
$can_be_personal = false;
break;
} else {
$targetPHID = head($target);
if ($targetPHID !== $rule->getAuthorPHID()) {
$can_be_personal = false;
break;
}
}
} else if ($target) {
if ($target !== $rule->getAuthorPHID()) {
$can_be_personal = false;
break;
}
}
}
if ($can_be_personal) {
$rule->setRuleType(HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
queryfx(
$rule->establishConnection('w'),
'UPDATE %T SET ruleType = %s WHERE id = %d',
$rule->getTableName(),
$rule->getRuleType(),
$rule->getID());
echo "Setting rule '" . $rule->getName() . "' to personal. ";
}
}
}
-echo "Done. ";
+$table->endReadLocking();
+$table->saveTransaction();
+echo "Done.\n";
diff --git a/resources/sql/patches/102.heraldcleanup.php b/resources/sql/patches/102.heraldcleanup.php
index 6589c7f0ef..22f198df86 100644
--- a/resources/sql/patches/102.heraldcleanup.php
+++ b/resources/sql/patches/102.heraldcleanup.php
@@ -1,35 +1,39 @@
<?php
echo "Cleaning up old Herald rule applied rows...\n";
+$table = new HeraldRule();
+$table->openTransaction();
+$table->beginReadLocking();
-$rules = id(new HeraldRule())->loadAll();
+$rules = $table->loadAll();
foreach ($rules as $key => $rule) {
$first_policy = HeraldRepetitionPolicyConfig::toInt(
HeraldRepetitionPolicyConfig::FIRST);
if ($rule->getRepetitionPolicy() != $first_policy) {
unset($rules[$key]);
}
}
-$conn_w = id(new HeraldRule())->establishConnection('w');
+$conn_w = $table->establishConnection('w');
$clause = '';
if ($rules) {
$clause = qsprintf(
$conn_w,
'WHERE ruleID NOT IN (%Ld)',
mpull($rules, 'getID'));
}
echo "This may take a moment";
do {
queryfx(
$conn_w,
'DELETE FROM %T %Q LIMIT 1000',
HeraldRule::TABLE_RULE_APPLIED,
$clause);
echo ".";
} while ($conn_w->getAffectedRows());
-echo "\n";
-echo "Done.\n";
+$table->endReadLocking();
+$table->saveTransaction();
+echo "\nDone.\n";
diff --git a/resources/sql/patches/111.commitauditmigration.php b/resources/sql/patches/111.commitauditmigration.php
index be734877c5..489a07d789 100644
--- a/resources/sql/patches/111.commitauditmigration.php
+++ b/resources/sql/patches/111.commitauditmigration.php
@@ -1,55 +1,58 @@
<?php
echo "Updating old commit authors...\n";
-
$table = new PhabricatorRepositoryCommit();
+$table->openTransaction();
+
$conn = $table->establishConnection('w');
$data = new PhabricatorRepositoryCommitData();
$commits = queryfx_all(
$conn,
'SELECT c.id id, c.authorPHID authorPHID, d.commitDetails details
FROM %T c JOIN %T d ON d.commitID = c.id
- WHERE c.authorPHID IS NULL',
+ WHERE c.authorPHID IS NULL
+ FOR UPDATE',
$table->getTableName(),
$data->getTableName());
foreach ($commits as $commit) {
$id = $commit['id'];
$details = json_decode($commit['details'], true);
$author_phid = idx($details, 'authorPHID');
if ($author_phid) {
queryfx(
$conn,
'UPDATE %T SET authorPHID = %s WHERE id = %d',
$table->getTableName(),
$author_phid,
$id);
echo "#{$id}\n";
}
}
+$table->saveTransaction();
echo "Done.\n";
echo "Updating old commit mailKeys...\n";
+$table->openTransaction();
-$table = new PhabricatorRepositoryCommit();
-$conn = $table->establishConnection('w');
$commits = queryfx_all(
$conn,
- 'SELECT id FROM %T WHERE mailKey = %s',
+ 'SELECT id FROM %T WHERE mailKey = %s FOR UPDATE',
$table->getTableName(),
'');
foreach ($commits as $commit) {
$id = $commit['id'];
queryfx(
$conn,
'UPDATE %T SET mailKey = %s WHERE id = %d',
$table->getTableName(),
Filesystem::readRandomCharacters(20),
$id);
echo "#{$id}\n";
}
+$table->saveTransaction();
echo "Done.\n";
diff --git a/resources/sql/patches/131.migraterevisionquery.php b/resources/sql/patches/131.migraterevisionquery.php
index 5d155d10ba..027edbaeb3 100644
--- a/resources/sql/patches/131.migraterevisionquery.php
+++ b/resources/sql/patches/131.migraterevisionquery.php
@@ -1,31 +1,35 @@
<?php
$table = new DifferentialRevision();
+$table->openTransaction();
+$table->beginReadLocking();
$conn_w = $table->establishConnection('w');
echo "Migrating revisions";
do {
- $revisions = id(new DifferentialRevision())
- ->loadAllWhere('branchName IS NULL LIMIT 1000');
+ $revisions = $table->loadAllWhere('branchName IS NULL LIMIT 1000');
foreach ($revisions as $revision) {
echo ".";
$diff = $revision->loadActiveDiff();
if (!$diff) {
continue;
}
$branch_name = $diff->getBranch();
$arc_project_phid = $diff->getArcanistProjectPHID();
queryfx(
$conn_w,
'UPDATE %T SET branchName = %s, arcanistProjectPHID = %s WHERE id = %d',
$table->getTableName(),
$branch_name,
$arc_project_phid,
$revision->getID());
}
} while (count($revisions) == 1000);
+
+$table->endReadLocking();
+$table->saveTransaction();
echo "\nDone.\n";
diff --git a/resources/sql/patches/20121209.xmacromigrate.php b/resources/sql/patches/20121209.xmacromigrate.php
index d31f40fd92..0372faafa7 100644
--- a/resources/sql/patches/20121209.xmacromigrate.php
+++ b/resources/sql/patches/20121209.xmacromigrate.php
@@ -1,18 +1,23 @@
<?php
echo "Giving image macros PHIDs";
-foreach (new LiskMigrationIterator(new PhabricatorFileImageMacro()) as $macro) {
+$table = new PhabricatorFileImageMacro();
+$table->openTransaction();
+
+foreach (new LiskMigrationIterator($table) as $macro) {
if ($macro->getPHID()) {
continue;
}
echo ".";
queryfx(
- $macro->establishConnection('r'),
+ $macro->establishConnection('w'),
'UPDATE %T SET phid = %s WHERE id = %d',
$macro->getTableName(),
$macro->generatePHID(),
$macro->getID());
}
+
+$table->saveTransaction();
echo "\nDone.\n";
diff --git a/resources/sql/patches/emailtableport.php b/resources/sql/patches/emailtableport.php
index 742b9203be..ba46e70916 100644
--- a/resources/sql/patches/emailtableport.php
+++ b/resources/sql/patches/emailtableport.php
@@ -1,33 +1,34 @@
<?php
echo "Migrating user emails...\n";
$table = new PhabricatorUser();
-$conn = $table->establishConnection('r');
+$table->openTransaction();
+$conn = $table->establishConnection('w');
$emails = queryfx_all(
$conn,
- 'SELECT phid, email FROM %T',
+ 'SELECT phid, email FROM %T LOCK IN SHARE MODE',
$table->getTableName());
$emails = ipull($emails, 'email', 'phid');
$etable = new PhabricatorUserEmail();
-$econn = $etable->establishConnection('w');
foreach ($emails as $phid => $email) {
// NOTE: Grandfather all existing email in as primary / verified. We generate
// verification codes because they are used for password resets, etc.
echo "Migrating '{$phid}'...\n";
queryfx(
- $econn,
+ $conn,
'INSERT INTO %T (userPHID, address, verificationCode, isVerified, isPrimary)
VALUES (%s, %s, %s, 1, 1)',
$etable->getTableName(),
$phid,
$email,
Filesystem::readRandomCharacters(24));
}
+$table->saveTransaction();
echo "Done.\n";
diff --git a/resources/sql/patches/migrate-differential-dependencies.php b/resources/sql/patches/migrate-differential-dependencies.php
index 16c7c0dbdb..83a9cab302 100644
--- a/resources/sql/patches/migrate-differential-dependencies.php
+++ b/resources/sql/patches/migrate-differential-dependencies.php
@@ -1,26 +1,30 @@
<?php
echo "Migrating differential dependencies to edges...\n";
-foreach (new LiskMigrationIterator(new DifferentialRevision()) as $rev) {
+$table = new DifferentialRevision();
+$table->openTransaction();
+
+foreach (new LiskMigrationIterator($table) as $rev) {
$id = $rev->getID();
echo "Revision {$id}: ";
$deps = $rev->getAttachedPHIDs(PhabricatorPHIDConstants::PHID_TYPE_DREV);
if (!$deps) {
echo "-\n";
continue;
}
$editor = new PhabricatorEdgeEditor();
$editor->setSuppressEvents(true);
foreach ($deps as $dep) {
$editor->addEdge(
$rev->getPHID(),
PhabricatorEdgeConfig::TYPE_DREV_DEPENDS_ON_DREV,
$dep);
}
$editor->save();
echo "OKAY\n";
}
+$table->saveTransaction();
echo "Done.\n";
diff --git a/resources/sql/patches/migrate-maniphest-dependencies.php b/resources/sql/patches/migrate-maniphest-dependencies.php
index 058a151a08..4e39e85987 100644
--- a/resources/sql/patches/migrate-maniphest-dependencies.php
+++ b/resources/sql/patches/migrate-maniphest-dependencies.php
@@ -1,26 +1,30 @@
<?php
echo "Migrating task dependencies to edges...\n";
-foreach (new LiskMigrationIterator(new ManiphestTask()) as $task) {
+$table = new ManiphestTask();
+$table->openTransaction();
+
+foreach (new LiskMigrationIterator($table) as $task) {
$id = $task->getID();
echo "Task {$id}: ";
$deps = $task->getAttachedPHIDs(PhabricatorPHIDConstants::PHID_TYPE_TASK);
if (!$deps) {
echo "-\n";
continue;
}
$editor = new PhabricatorEdgeEditor();
$editor->setSuppressEvents(true);
foreach ($deps as $dep) {
$editor->addEdge(
$task->getPHID(),
PhabricatorEdgeConfig::TYPE_TASK_DEPENDS_ON_TASK,
$dep);
}
$editor->save();
echo "OKAY\n";
}
+$table->saveTransaction();
echo "Done.\n";
diff --git a/resources/sql/patches/migrate-maniphest-revisions.php b/resources/sql/patches/migrate-maniphest-revisions.php
index 19a5ec5590..29f8eef0de 100644
--- a/resources/sql/patches/migrate-maniphest-revisions.php
+++ b/resources/sql/patches/migrate-maniphest-revisions.php
@@ -1,26 +1,29 @@
<?php
echo "Migrating task revisions to edges...\n";
-foreach (new LiskMigrationIterator(new ManiphestTask()) as $task) {
+$table = new ManiphestTask();
+$table->establishConnection('w');
+
+foreach (new LiskMigrationIterator($table) as $task) {
$id = $task->getID();
echo "Task {$id}: ";
$revs = $task->getAttachedPHIDs(PhabricatorPHIDConstants::PHID_TYPE_DREV);
if (!$revs) {
echo "-\n";
continue;
}
$editor = new PhabricatorEdgeEditor();
$editor->setSuppressEvents(true);
foreach ($revs as $rev) {
$editor->addEdge(
$task->getPHID(),
PhabricatorEdgeConfig::TYPE_TASK_HAS_RELATED_DREV,
$rev);
}
$editor->save();
echo "OKAY\n";
}
echo "Done.\n";
diff --git a/resources/sql/patches/migrate-project-edges.php b/resources/sql/patches/migrate-project-edges.php
index d10da778eb..f64fa40efd 100644
--- a/resources/sql/patches/migrate-project-edges.php
+++ b/resources/sql/patches/migrate-project-edges.php
@@ -1,33 +1,36 @@
<?php
echo "Migrating project members to edges...\n";
-foreach (new LiskMigrationIterator(new PhabricatorProject()) as $proj) {
+$table = new PhabricatorProject();
+$table->establishConnection('w');
+
+foreach (new LiskMigrationIterator($table) as $proj) {
$id = $proj->getID();
echo "Project {$id}: ";
$members = queryfx_all(
- $proj->establishConnection('r'),
+ $proj->establishConnection('w'),
'SELECT userPHID FROM %T WHERE projectPHID = %s',
'project_affiliation',
$proj->getPHID());
if (!$members) {
echo "-\n";
continue;
}
$members = ipull($members, 'userPHID');
$editor = new PhabricatorEdgeEditor();
$editor->setSuppressEvents(true);
foreach ($members as $user_phid) {
$editor->addEdge(
$proj->getPHID(),
PhabricatorEdgeConfig::TYPE_PROJ_MEMBER,
$user_phid);
}
$editor->save();
echo "OKAY\n";
}
echo "Done.\n";
diff --git a/resources/sql/patches/ponder-mailkey-populate.php b/resources/sql/patches/ponder-mailkey-populate.php
index 70b36325b5..bdae8f83a0 100644
--- a/resources/sql/patches/ponder-mailkey-populate.php
+++ b/resources/sql/patches/ponder-mailkey-populate.php
@@ -1,21 +1,25 @@
<?php
echo "Populating Questions with mail keys...\n";
-foreach (new LiskMigrationIterator(new PonderQuestion()) as $question) {
+$table = new PonderQuestion();
+$table->openTransaction();
+
+foreach (new LiskMigrationIterator($table) as $question) {
$id = $question->getID();
echo "Question {$id}: ";
if (!$question->getMailKey()) {
queryfx(
$question->establishConnection('w'),
'UPDATE %T SET mailKey = %s WHERE id = %d',
$question->getTableName(),
Filesystem::readRandomCharacters(20),
$id);
echo "Generated Key\n";
} else {
echo "-\n";
}
}
+$table->saveTransaction();
echo "Done.\n";

File Metadata

Mime Type
text/x-diff
Expires
Tue, Dec 2, 3:37 AM (22 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
431593
Default Alt Text
(19 KB)

Event Timeline