Skip to content

Commit

Permalink
Refactored code where SetupHelper::runOcc method is used
Browse files Browse the repository at this point in the history
  • Loading branch information
grgprarup committed Mar 3, 2023
1 parent 60ef7bd commit 9298cd1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 212 deletions.
45 changes: 9 additions & 36 deletions tests/TestHelpers/LoggingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ public static function getLogFilePath(
// Currently we don't interact with the log file on reva or OCIS
return "";
}
$result = SetupHelper::runOcc(
['log:owncloud'],
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ($result["code"] != 0) {
throw new Exception(
"could not get owncloud log file information" .
Expand Down Expand Up @@ -135,10 +132,7 @@ public static function getLogLevel(
if (OcisHelper::isTestingOnOcisOrReva()) {
return "debug";
}
$result = SetupHelper::runOcc(
["log:manage"],
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ($result["code"] != 0) {
throw new Exception(
"could not get log level " . $result ["stdOut"] . " " .
Expand Down Expand Up @@ -170,10 +164,7 @@ public static function setLogLevel(
if (!\in_array($logLevel, self::LOG_LEVEL_ARRAY)) {
throw new InvalidArgumentException("invalid log level");
}
$result = SetupHelper::runOcc(
["log:manage", "--level=$logLevel"],
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ($result["code"] != 0) {
throw new Exception(
"could not set log level " . $result ["stdOut"] . " " .
Expand All @@ -196,10 +187,7 @@ public static function getLogBackend(
if (OcisHelper::isTestingOnOcisOrReva()) {
return "errorlog";
}
$result = SetupHelper::runOcc(
["log:manage"],
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ($result["code"] != 0) {
throw new Exception(
"could not get log backend " . $result ["stdOut"] . " " .
Expand Down Expand Up @@ -236,10 +224,7 @@ public static function setLogBackend(
// Currently we can't manage log file settings on reva or OCIS
return;
}
$result = SetupHelper::runOcc(
["log:manage", "--backend=$backend"],
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ($result["code"] != 0) {
throw new Exception(
"could not set log backend " . $result ["stdOut"] . " " .
Expand All @@ -262,10 +247,7 @@ public static function getLogTimezone(
if (OcisHelper::isTestingOnOcisOrReva()) {
return "UTC";
}
$result = SetupHelper::runOcc(
["log:manage"],
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ($result["code"] != 0) {
throw new Exception(
"could not get log timezone " . $result ["stdOut"] . " " .
Expand Down Expand Up @@ -299,10 +281,7 @@ public static function setLogTimezone(
// Currently we can't manage log file settings on reva or OCIS
return;
}
$result = SetupHelper::runOcc(
["log:manage", "--timezone=$timezone"],
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ($result["code"] != 0) {
throw new Exception(
"could not set log timezone " . $result ["stdOut"] . " " .
Expand Down Expand Up @@ -384,10 +363,7 @@ public static function restoreLoggingStatus(
}

if (\count($commands) > 1) {
$result = SetupHelper::runOcc(
$commands,
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ($result["code"] != 0) {
throw new Exception(
"could not restore log status " . $result ["stdOut"] . " " .
Expand Down Expand Up @@ -415,10 +391,7 @@ public static function getLogInfo(
"timezone" => "UTC"
];
}
$result = SetupHelper::runOcc(
["log:manage"],
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ($result["code"] != 0) {
throw new Exception(
"could not get log level " . $result ["stdOut"] . " " .
Expand Down
102 changes: 16 additions & 86 deletions tests/TestHelpers/SetupHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ public static function createUser(
$occCommand = \array_merge($occCommand, ["--email", $email]);
}
\putenv("OC_PASS=" . $password);
return self::runOcc(
\array_merge($occCommand, [$userName]),
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}

/**
Expand All @@ -98,10 +95,7 @@ public static function deleteUser(
?string $userName,
?string $xRequestId = ''
):array {
return self::runOcc(
['user:delete', $userName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}

/**
Expand All @@ -122,10 +116,7 @@ public static function changeUserSetting(
?string $value,
?string $xRequestId = ''
):array {
return self::runOcc(
['user:setting', '--value ' . $value, $userName, $app, $key],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}

/**
Expand All @@ -141,10 +132,7 @@ public static function createGroup(
?string $groupName,
?string $xRequestId = ''
):array {
return self::runOcc(
['group:add', $groupName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}

/**
Expand All @@ -162,10 +150,7 @@ public static function addUserToGroup(
?string $userName,
?string $xRequestId = ''
):array {
return self::runOcc(
['group:add-member', '--member', $userName, $groupName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}

/**
Expand All @@ -183,10 +168,7 @@ public static function removeUserFromGroup(
?string $userName,
?string $xRequestId = ''
):array {
return self::runOcc(
['group:remove-member', '--member', $userName, $groupName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}

/**
Expand All @@ -202,10 +184,7 @@ public static function deleteGroup(
?string $groupName,
?string $xRequestId = ''
):array {
return self::runOcc(
['group:delete', $groupName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}

/**
Expand All @@ -219,10 +198,7 @@ public static function getGroups(
?string $xRequestId = ''
):array {
return \json_decode(
self::runOcc(
['group:list', '--output=json'],
$xRequestId
)['stdOut']
['code' => '', 'stdOut' => '', 'stdErr' => '' ]['stdOut']
);
}
/**
Expand Down Expand Up @@ -653,13 +629,7 @@ public static function readSkeletonFile(
);

//find the absolute path of the currently set skeletondirectory
$occResponse = self::runOcc(
['config:system:get', 'skeletondirectory'],
$xRequestId,
$adminUsername,
$adminPassword,
$baseUrl
);
$occResponse = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
if ((int) $occResponse['code'] !== 0) {
throw new \Exception(
"could not get current skeletondirectory. " . $occResponse['stdErr']
Expand Down Expand Up @@ -700,10 +670,7 @@ public static function enableApp(
?string $appName,
?string $xRequestId = ''
):array {
return self::runOcc(
['app:enable', $appName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}

/**
Expand All @@ -719,10 +686,7 @@ public static function disableApp(
?string $appName,
?string $xRequestId = ''
):array {
return self::runOcc(
['app:disable', $appName],
$xRequestId
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}

/**
Expand All @@ -738,10 +702,7 @@ public static function isAppEnabled(
?string $appName,
?string $xRequestId = ''
):bool {
$result = self::runOcc(
['app:list', '^' . $appName . '$'],
$xRequestId
);
$result = ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
return \strtolower(\substr($result['stdOut'], 0, 7)) === 'enabled';
}

Expand Down Expand Up @@ -895,17 +856,7 @@ public static function createLocalStorageMount(
self::$adminPassword,
$xRequestId
);
$result = self::runOcc(
[
'files_external:create',
$mount,
'local',
'null::null',
'-c',
'datadir=' . $serverRoot . '/' . $mountPath
],
$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)) {
Expand Down Expand Up @@ -955,14 +906,7 @@ public static function getSystemConfig(

$args[] = '--no-ansi';

return self::runOcc(
$args,
$xRequestId,
$adminUsername,
$adminPassword,
$baseUrl,
$ocPath
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}

/**
Expand Down Expand Up @@ -1012,14 +956,7 @@ public static function setSystemConfig(
if ($baseUrl === null) {
$baseUrl = self::$baseUrl;
}
return self::runOcc(
$args,
$xRequestId,
$adminUsername,
$adminPassword,
$baseUrl,
$ocPath
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}

/**
Expand Down Expand Up @@ -1106,13 +1043,6 @@ public static function deleteSystemConfig(
if ($baseUrl === null) {
$baseUrl = self::$baseUrl;
}
return SetupHelper::runOcc(
$args,
$xRequestId,
$adminUsername,
$adminPassword,
$baseUrl,
$ocPath
);
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
}
}
Loading

0 comments on commit 9298cd1

Please sign in to comment.