Cleaned up orphaned methods in SetupHelper
This commit is contained in:
@@ -52,155 +52,6 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
|
||||
*/
|
||||
private static $adminPassword = null;
|
||||
|
||||
/**
|
||||
* creates a user
|
||||
*
|
||||
* @param string|null $userName
|
||||
* @param string|null $password
|
||||
* @param string|null $xRequestId
|
||||
* @param string|null $displayName
|
||||
* @param string|null $email
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr"
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function createUser(
|
||||
?string $userName,
|
||||
?string $password,
|
||||
?string $xRequestId = '',
|
||||
?string $displayName = null,
|
||||
?string $email = null
|
||||
):array {
|
||||
$occCommand = ['user:add', '--password-from-env'];
|
||||
if ($displayName !== null) {
|
||||
$occCommand = \array_merge($occCommand, ["--display-name", $displayName]);
|
||||
}
|
||||
if ($email !== null) {
|
||||
$occCommand = \array_merge($occCommand, ["--email", $email]);
|
||||
}
|
||||
\putenv("OC_PASS=" . $password);
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes a user
|
||||
*
|
||||
* @param string|null $userName
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr"
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function deleteUser(
|
||||
?string $userName,
|
||||
?string $xRequestId = ''
|
||||
):array {
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string|null $userName
|
||||
* @param string|null $app
|
||||
* @param string|null $key
|
||||
* @param string|null $value
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return string[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function changeUserSetting(
|
||||
?string $userName,
|
||||
?string $app,
|
||||
?string $key,
|
||||
?string $value,
|
||||
?string $xRequestId = ''
|
||||
):array {
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a group
|
||||
*
|
||||
* @param string|null $groupName
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr"
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function createGroup(
|
||||
?string $groupName,
|
||||
?string $xRequestId = ''
|
||||
):array {
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* adds an existing user to a group, creating the group if it does not exist
|
||||
*
|
||||
* @param string|null $groupName
|
||||
* @param string|null $userName
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr"
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function addUserToGroup(
|
||||
?string $groupName,
|
||||
?string $userName,
|
||||
?string $xRequestId = ''
|
||||
):array {
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* removes a user from a group
|
||||
*
|
||||
* @param string|null $groupName
|
||||
* @param string|null $userName
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr"
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function removeUserFromGroup(
|
||||
?string $groupName,
|
||||
?string $userName,
|
||||
?string $xRequestId = ''
|
||||
):array {
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes a group
|
||||
*
|
||||
* @param string|null $groupName
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr"
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function deleteGroup(
|
||||
?string $groupName,
|
||||
?string $xRequestId = ''
|
||||
):array {
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return string[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getGroups(
|
||||
?string $xRequestId = ''
|
||||
):array {
|
||||
return \json_decode(
|
||||
['code' => '', 'stdOut' => '', 'stdErr' => '' ]['stdOut']
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param HookScope $scope
|
||||
@@ -253,21 +104,6 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
|
||||
self::$ocPath = self::normaliseOcPath($ocPath);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string path to the testing app occ endpoint
|
||||
* @throws Exception if ocPath has not been set yet
|
||||
*/
|
||||
public static function getOcPath():?string {
|
||||
if (self::$ocPath === null) {
|
||||
throw new Exception(
|
||||
"getOcPath called before ocPath is set by init"
|
||||
);
|
||||
}
|
||||
|
||||
return self::$ocPath;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string|null $baseUrl
|
||||
@@ -657,298 +493,6 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
|
||||
return $localContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* enables an app
|
||||
*
|
||||
* @param string|null $appName
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr"
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function enableApp(
|
||||
?string $appName,
|
||||
?string $xRequestId = ''
|
||||
):array {
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* disables an app
|
||||
*
|
||||
* @param string|null $appName
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr"
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function disableApp(
|
||||
?string $appName,
|
||||
?string $xRequestId = ''
|
||||
):array {
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if an app is currently enabled
|
||||
*
|
||||
* @param string|null $appName
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return bool true if enabled, false if disabled or nonexistent
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function isAppEnabled(
|
||||
?string $appName,
|
||||
?string $xRequestId = ''
|
||||
):bool {
|
||||
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
return \strtolower(\substr($result['stdOut'], 0, 7)) === 'enabled';
|
||||
}
|
||||
|
||||
/**
|
||||
* lists app status (enabled or disabled)
|
||||
*
|
||||
* @param string|null $appName
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return bool true if the app needed to be enabled, false otherwise
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function enableAppIfNotEnabled(
|
||||
?string $appName,
|
||||
?string $xRequestId = ''
|
||||
):bool {
|
||||
if (!self::isAppEnabled($appName, $xRequestId)) {
|
||||
self::enableApp(
|
||||
$appName,
|
||||
$xRequestId
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a list of occ commands at once
|
||||
*
|
||||
* @param array|null $commands
|
||||
* @param string|null $xRequestId
|
||||
* @param string|null $adminUsername
|
||||
* @param string|null $adminPassword
|
||||
* @param string|null $baseUrl
|
||||
*
|
||||
* @return array
|
||||
* @throws GuzzleException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function runBulkOcc(
|
||||
?array $commands,
|
||||
?string $xRequestId = '',
|
||||
?string $adminUsername = null,
|
||||
?string $adminPassword = null,
|
||||
?string $baseUrl = null
|
||||
):array {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $xRequestId
|
||||
*
|
||||
* @return ResponseInterface|null
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function resetOpcache(
|
||||
?string $baseUrl,
|
||||
?string $user,
|
||||
?string $password,
|
||||
?string $xRequestId = ''
|
||||
):?ResponseInterface {
|
||||
try {
|
||||
return OcsApiHelper::sendRequest(
|
||||
$baseUrl,
|
||||
$user,
|
||||
$password,
|
||||
"DELETE",
|
||||
"/apps/testing/api/v1/opcache",
|
||||
$xRequestId
|
||||
);
|
||||
} catch (ServerException $e) {
|
||||
echo "could not reset opcache, if tests fail try to set " .
|
||||
"'opcache.revalidate_freq=0' in the php.ini file\n";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create local storage mount
|
||||
*
|
||||
* @param string|null $mount (name of local storage mount)
|
||||
* @param string|null $xRequestId
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr", "storageId"
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function createLocalStorageMount(
|
||||
?string $mount,
|
||||
?string $xRequestId = ''
|
||||
):array {
|
||||
$mountPath = TEMPORARY_STORAGE_DIR_ON_REMOTE_SERVER . "/$mount";
|
||||
SetupHelper::mkDirOnServer(
|
||||
$mountPath,
|
||||
$xRequestId
|
||||
);
|
||||
// files_external:create requires absolute path
|
||||
$serverRoot = self::getServerRoot(
|
||||
self::$baseUrl,
|
||||
self::$adminUsername,
|
||||
self::$adminPassword,
|
||||
$xRequestId
|
||||
);
|
||||
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
// stdOut should have a string like "Storage created with id 65"
|
||||
$storageIdWords = \explode(" ", \trim($result['stdOut']));
|
||||
if (\array_key_exists(4, $storageIdWords)) {
|
||||
$result['storageId'] = (int)$storageIdWords[4];
|
||||
} else {
|
||||
// presumably something went wrong with the files_external:create command
|
||||
// so return "unknown" to the caller. The result array has the command exit
|
||||
// code and stdErr output etc., so the caller can process what it likes
|
||||
// of that information to work out what went wrong.
|
||||
$result['storageId'] = "unknown";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a system config setting, including status code, output and standard
|
||||
* error output.
|
||||
*
|
||||
* @param string|null $key
|
||||
* @param string|null $xRequestId
|
||||
* @param string|null $output e.g. json
|
||||
* @param string|null $adminUsername
|
||||
* @param string|null $adminPassword
|
||||
* @param string|null $baseUrl
|
||||
* @param string|null $ocPath
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr"
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function getSystemConfig(
|
||||
?string $key,
|
||||
?string $xRequestId = '',
|
||||
?string $output = null,
|
||||
?string $adminUsername = null,
|
||||
?string $adminPassword = null,
|
||||
?string $baseUrl = null,
|
||||
?string $ocPath = null
|
||||
):array {
|
||||
$args = [];
|
||||
$args[] = 'config:system:get';
|
||||
$args[] = $key;
|
||||
|
||||
if ($output !== null) {
|
||||
$args[] = '--output';
|
||||
$args[] = $output;
|
||||
}
|
||||
|
||||
$args[] = '--no-ansi';
|
||||
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a system config setting
|
||||
*
|
||||
* @param string|null $key
|
||||
* @param string|null $value
|
||||
* @param string|null $xRequestId
|
||||
* @param string|null $type e.g. boolean or json
|
||||
* @param string|null $output e.g. json
|
||||
* @param string|null $adminUsername
|
||||
* @param string|null $adminPassword
|
||||
* @param string|null $baseUrl
|
||||
* @param string|null $ocPath
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr"
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function setSystemConfig(
|
||||
?string $key,
|
||||
?string $value,
|
||||
?string $xRequestId = '',
|
||||
?string $type = null,
|
||||
?string $output = null,
|
||||
?string $adminUsername = null,
|
||||
?string $adminPassword = null,
|
||||
?string $baseUrl = null,
|
||||
?string $ocPath = null
|
||||
):array {
|
||||
$args = [];
|
||||
$args[] = 'config:system:set';
|
||||
$args[] = $key;
|
||||
$args[] = '--value';
|
||||
$args[] = $value;
|
||||
|
||||
if ($type !== null) {
|
||||
$args[] = '--type';
|
||||
$args[] = $type;
|
||||
}
|
||||
|
||||
if ($output !== null) {
|
||||
$args[] = '--output';
|
||||
$args[] = $output;
|
||||
}
|
||||
|
||||
$args[] = '--no-ansi';
|
||||
if ($baseUrl === null) {
|
||||
$baseUrl = self::$baseUrl;
|
||||
}
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a system config setting
|
||||
*
|
||||
* @param string|null $key
|
||||
* @param string|null $xRequestId
|
||||
* @param string|null $output e.g. json
|
||||
* @param string|null $adminUsername
|
||||
* @param string|null $adminPassword
|
||||
* @param string|null $baseUrl
|
||||
* @param string|null $ocPath
|
||||
*
|
||||
* @return string
|
||||
* @throws GuzzleException if parameters have not been provided yet or the testing app is not enabled
|
||||
*/
|
||||
public static function getSystemConfigValue(
|
||||
?string $key,
|
||||
?string $xRequestId = '',
|
||||
?string $output = null,
|
||||
?string $adminUsername = null,
|
||||
?string $adminPassword = null,
|
||||
?string $baseUrl = null,
|
||||
?string $ocPath = null
|
||||
):string {
|
||||
if ($baseUrl === null) {
|
||||
$baseUrl = self::$baseUrl;
|
||||
}
|
||||
return self::getSystemConfig(
|
||||
$key,
|
||||
$xRequestId,
|
||||
$output,
|
||||
$adminUsername,
|
||||
$adminPassword,
|
||||
$baseUrl,
|
||||
$ocPath
|
||||
)['stdOut'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all lines containing the given text
|
||||
*
|
||||
@@ -966,36 +510,4 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a system config setting
|
||||
*
|
||||
* @param string|null $key
|
||||
* @param string|null $xRequestId
|
||||
* @param string|null $adminUsername
|
||||
* @param string|null $adminPassword
|
||||
* @param string|null $baseUrl
|
||||
* @param string|null $ocPath
|
||||
*
|
||||
* @return string[] associated array with "code", "stdOut", "stdErr"
|
||||
* @throws GuzzleException if parameters have not been provided yet or the testing app is not enabled
|
||||
*/
|
||||
public static function deleteSystemConfig(
|
||||
?string $key,
|
||||
?string $xRequestId = '',
|
||||
?string $adminUsername = null,
|
||||
?string $adminPassword = null,
|
||||
?string $baseUrl = null,
|
||||
?string $ocPath = null
|
||||
):array {
|
||||
$args = [];
|
||||
$args[] = 'config:system:delete';
|
||||
$args[] = $key;
|
||||
|
||||
$args[] = '--no-ansi';
|
||||
if ($baseUrl === null) {
|
||||
$baseUrl = self::$baseUrl;
|
||||
}
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user