Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 376c02f

Browse files
committed
Changed function callbacks syntax to support PHP7.3 (#13)
1 parent 12627c7 commit 376c02f

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

lib/Service/CleanupService.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* You should have received a copy of the GNU Affero General Public License
2525
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26-
*!
26+
*
2727
*/
2828

2929
namespace OCA\MediaDC\Service;
@@ -50,15 +50,24 @@ public function __construct(IDBConnection $db, ISchemaWrapper $schema)
5050
}
5151

5252
public function dropAppTables() {
53-
$tables = array_filter($this->schema->getTableNames(),
54-
fn($tableName): bool => strpos($tableName, Application::APP_ID) !== false
55-
);
53+
$tables = array_filter($this->schema->getTableNames(), '\OCA\MediaDC\Service\CleanupService::tablesCallback');
5654
foreach ($tables as $table) {
5755
$this->db->dropTable($table);
5856
}
5957
$this->removeAppMigrations();
6058
}
6159

60+
/**
61+
* Callback for tables filter
62+
*
63+
* @param string $tableName
64+
*
65+
* @return bool
66+
*/
67+
static function tablesCallback($tableName) {
68+
return strpos($tableName, Application::APP_ID) !== false;
69+
}
70+
6271
private function removeAppMigrations() {
6372
/** @var IQueryBuilder */
6473
$qb = $this->db->getQueryBuilder();

lib/Service/CollectorService.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function restart($params = []) {
174174
/** @var Setting */
175175
$pyLimitSetting = $this->settingsMapper->findByName('python_limit');
176176
$processesRunning = $this->tasksMapper->findAllRunning();
177-
$taskIdsRunning = array_map(fn($task) => $task->getId(), $processesRunning);
177+
$taskIdsRunning = array_map('\OCA\MediaDC\Service\CollectorService::taskIdCallback', $processesRunning);
178178
/** @var CollectorTask */
179179
$collectorTask = $this->tasksMapper->find($taskId);
180180
$taskData = $this->getTargetDirectoriesData($params['targetDirectoryIds'], intval($params['collectorSettings']['target_mtype']), $excludeList);
@@ -213,6 +213,17 @@ public function restart($params = []) {
213213
return ['success' => $collectorTask !== null, 'queued' => $queuedTask !== null];
214214
}
215215

216+
/**
217+
* Callback to extract ColectorTask id
218+
*
219+
* @param CollectorTask $task
220+
*
221+
* @return int
222+
*/
223+
static function taskIdCallback($task) {
224+
return $task->getId();
225+
}
226+
216227
/**
217228
* Terminate CollectorTask background Python process
218229
*

lib/Service/PythonService.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,13 @@ public function __construct(SettingMapper $settingMapper, IConfig $config)
7474
*/
7575
public function run($scriptName, $scriptParams, $nonBlocking = false, $env = []) {
7676
if (count($scriptParams) > 0) {
77-
$callback = fn(string $k, string $v): string => $v !== '' ? "$k $v " : "$k";
78-
$params = array_map($callback, array_keys($scriptParams), array_values($scriptParams));
77+
$params = array_map('\OCA\MediaDC\Service\PythonService::scriptParamsCallback', array_keys($scriptParams), array_values($scriptParams));
7978
$cmd = $this->pythonCommand . ' ' . $this->cwd . $scriptName . ' ' . join(' ', $params);
8079
} else {
8180
$cmd = $this->pythonCommand . ' ' . $this->cwd . $scriptName;
8281
}
8382
if (count($env) > 0) {
84-
$envVariables = join(' ', array_map(fn(string $k, string $v): string => "$k=\"$v\" ", array_keys($env), array_values($env)));
83+
$envVariables = join(' ', array_map('\OCA\MediaDC\Service\PythonService::scriptEnvsCallback', array_keys($env), array_values($env)));
8584
} else {
8685
$envVariables = '';
8786
}
@@ -96,6 +95,30 @@ public function run($scriptName, $scriptParams, $nonBlocking = false, $env = [])
9695
}
9796
}
9897

98+
/**
99+
* Callback for concatinating Python script params
100+
*
101+
* @param string $key
102+
* @param string $value
103+
*
104+
* @return string
105+
*/
106+
static function scriptParamsCallback($key, $value) {
107+
return $value !== '' ? "$key $value " : "$key";
108+
}
109+
110+
/**
111+
* Callback for concatinating Python environment variables
112+
*
113+
* @param string $key
114+
* @param string $value
115+
*
116+
* @return string
117+
*/
118+
static function scriptEnvsCallback($key, $value) {
119+
return "$key=\"$value\" ";
120+
}
121+
99122
/**
100123
* @param string @listName
101124
*

0 commit comments

Comments
 (0)