@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<?php
2
3/**
4 * Used by unit tests to build storage fixtures.
5 */
6final class PhabricatorStorageFixtureScopeGuard extends Phobject {
7
8 private $name;
9
10 public function __construct($name) {
11 $this->name = $name;
12
13 execx(
14 'php %s upgrade --force --namespace %s',
15 $this->getStorageBinPath(),
16 $this->name);
17
18 PhabricatorLiskDAO::pushStorageNamespace($name);
19
20 // Destructor is not called with fatal error.
21 register_shutdown_function(array($this, 'destroy'));
22 }
23
24 public function destroy() {
25 PhabricatorLiskDAO::popStorageNamespace();
26
27 // NOTE: We need to close all connections before destroying the databases.
28 // If we do not, the "DROP DATABASE ..." statements may hang, waiting for
29 // our connections to close.
30 PhabricatorLiskDAO::closeAllConnections();
31
32 execx(
33 'php %s destroy --force --namespace %s',
34 $this->getStorageBinPath(),
35 $this->name);
36 }
37
38 private function getStorageBinPath() {
39 $root = dirname(phutil_get_library_root('phabricator'));
40 return $root.'/scripts/sql/manage_storage.php';
41 }
42
43}