1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 21:32:43 +01:00

Allow LiskDAO to be forced to use a specific connection

Summary:
Ref T7522. This seems like the least-bad approach to a messy issue:

  - When backfilling accounts from an imported instance, I need to write ExternalAccount rows to the instance to link instance accounts with upstream accounts.
  - We do this in the daemons in some other cases, which lets us run all the code in the context of the instance. However, I really want to do this in-process here because it's way way simpler and we need to do writes to //both// the instance and the upstream, and they're interleaved, and they depend on one another.
  - I can hard-code the query with `qsprintf()` but that feels like 100x worse than this.

This allows me to do this:

```
id(new PhabricatorExternalAccount())
  ->setForcedConnnection($instance_conn)
  ->...
  ->save();
```

...and get a write to the instance database, which is at least not completely a minefield.

Test Plan: Backfilled instance accounts and got interleaved instance and upstream writes as expected.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7522

Differential Revision: https://secure.phabricator.com/D12098
This commit is contained in:
epriestley 2015-03-17 14:43:08 -07:00
parent 6fc867d382
commit 827c0ce081

View file

@ -188,6 +188,7 @@ abstract class LiskDAO {
private static $transactionIsolationLevel = 0; private static $transactionIsolationLevel = 0;
private $ephemeral = false; private $ephemeral = false;
private $forcedConnection;
private static $connections = array(); private static $connections = array();
@ -280,6 +281,21 @@ abstract class LiskDAO {
} }
/**
* Force an object to use a specific connection.
*
* This overrides all connection management and forces the object to use
* a specific connection when interacting with the database.
*
* @param AphrontDatabaseConnection Connection to force this object to use.
* @task conn
*/
public function setForcedConnection(AphrontDatabaseConnection $connection) {
$this->forcedConnection = $connection;
return $this;
}
/* -( Configuring Lisk )--------------------------------------------------- */ /* -( Configuring Lisk )--------------------------------------------------- */
@ -941,6 +957,10 @@ abstract class LiskDAO {
throw new Exception("Unknown mode '{$mode}', should be 'r' or 'w'."); throw new Exception("Unknown mode '{$mode}', should be 'r' or 'w'.");
} }
if ($this->forcedConnection) {
return $this->forcedConnection;
}
if (self::shouldIsolateAllLiskEffectsToCurrentProcess()) { if (self::shouldIsolateAllLiskEffectsToCurrentProcess()) {
$mode = 'isolate-'.$mode; $mode = 'isolate-'.$mode;