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