@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+20
+20
src/infrastructure/storage/lisk/LiskDAO.php
··· 188 188 private static $transactionIsolationLevel = 0; 189 189 190 190 private $ephemeral = false; 191 + private $forcedConnection; 191 192 192 193 private static $connections = array(); 193 194 ··· 276 277 } 277 278 278 279 self::$connections[$key] = $connection; 280 + return $this; 281 + } 282 + 283 + 284 + /** 285 + * Force an object to use a specific connection. 286 + * 287 + * This overrides all connection management and forces the object to use 288 + * a specific connection when interacting with the database. 289 + * 290 + * @param AphrontDatabaseConnection Connection to force this object to use. 291 + * @task conn 292 + */ 293 + public function setForcedConnection(AphrontDatabaseConnection $connection) { 294 + $this->forcedConnection = $connection; 279 295 return $this; 280 296 } 281 297 ··· 939 955 public function establishConnection($mode, $force_new = false) { 940 956 if ($mode != 'r' && $mode != 'w') { 941 957 throw new Exception("Unknown mode '{$mode}', should be 'r' or 'w'."); 958 + } 959 + 960 + if ($this->forcedConnection) { 961 + return $this->forcedConnection; 942 962 } 943 963 944 964 if (self::shouldIsolateAllLiskEffectsToCurrentProcess()) {