Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Core/TempFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public static function getTempFolder($base)
// Append php version to username folder to avoid issues when upgrading php
$folderName .= '-' . preg_replace('/[^\w\-\.+]+/', '-', PHP_VERSION);

// Append paratest token to the folder name
if (($token = getenv('TEST_TOKEN')) !== false) {
$folderName .= '-' . $token;
}

// The actual temp folder is a subfolder of getTempParentFolder()
$subfolder = Path::join($parent, $folderName);

Expand Down
11 changes: 9 additions & 2 deletions src/ORM/Connect/TempDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ public function __construct($name = DB::CONN_PRIMARY)
*/
protected function isDBTemp($name)
{
$prefix = Environment::getEnv('SS_DATABASE_PREFIX') ?: 'ss_';
$prefix = preg_quote(Environment::getEnv('SS_DATABASE_PREFIX') ?: 'ss_', '/') . '([0-9]+_)?';

$result = preg_match(
sprintf('/^%stmpdb_[0-9]+_[0-9]+$/i', preg_quote($prefix ?? '', '/')),
sprintf('/^%stmpdb_[0-9]+_[0-9]+$/i', $prefix),
$name ?? ''
);

return $result === 1;
}

Expand Down Expand Up @@ -198,6 +200,11 @@ public function build()
// Create a temporary database, and force the connection to use UTC for time
$dbConn = $this->getConn();
$prefix = Environment::getEnv('SS_DATABASE_PREFIX') ?: 'ss_';

if (($token = getenv('TEST_TOKEN')) !== false) {
$prefix .= $token . '_';
}

do {
$dbname = strtolower(sprintf('%stmpdb_%s_%s', $prefix, time(), rand(1000000, 9999999)));
} while ($dbConn->databaseExists($dbname));
Expand Down
Loading