From 3b06bd789f683938a1cad684281b7578433c4f33 Mon Sep 17 00:00:00 2001 From: Andrey Borysenko Date: Tue, 23 Apr 2024 21:12:15 +0300 Subject: [PATCH] fix(occ): incorrect type of field in ExAppOccCommand (#278) Should fix incorrect type handling by different DBMS during ExApp occ command registration. Signed-off-by: Andrey Borysenko Signed-off-by: Alexander Piskun --- .github/workflows/tests.yml | 12 ++++++++---- docs/tech_details/api/occ_command.rst | 4 ++-- lib/Controller/OccCommandController.php | 4 ++-- lib/Db/Console/ExAppOccCommand.php | 8 +++++--- lib/Db/Console/ExAppOccCommandMapper.php | 2 +- lib/Db/ExAppEventsListenerMapper.php | 2 +- lib/Db/SpeechToText/SpeechToTextProviderMapper.php | 2 +- .../TextProcessing/TextProcessingProviderMapper.php | 2 +- lib/Db/Translation/TranslationProvider.php | 2 ++ lib/Db/Translation/TranslationProviderMapper.php | 2 +- lib/Db/UI/FilesActionsMenuMapper.php | 2 +- lib/Db/UI/SettingsFormMapper.php | 2 +- lib/Db/UI/TopMenuMapper.php | 2 +- lib/Fetcher/ExAppArchiveFetcher.php | 4 +--- lib/Migration/Version2205Date20240411124836.php | 4 +++- lib/Service/ExAppOccService.php | 4 ++-- 16 files changed, 33 insertions(+), 25 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 862c2a18..e972c99d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -270,7 +270,11 @@ jobs: nc-py-api-oci: runs-on: ubuntu-22.04 - name: NC_Py_API • stable28 • 8.2 • Oracle + name: NC_Py_API • ${{ matrix.server-version }} • 8.2 • Oracle + strategy: + fail-fast: false + matrix: + server-version: [ 'stable28', 'stable29' ] services: oracle: @@ -300,13 +304,13 @@ jobs: with: submodules: true repository: nextcloud/server - ref: stable28 + ref: ${{ matrix.server-version }} - name: Checkout Notifications uses: actions/checkout@v3 with: repository: nextcloud/notifications - ref: stable28 + ref: ${{ matrix.server-version }} path: apps/notifications - name: Checkout AppAPI @@ -376,7 +380,7 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - name: oci_nc_py_api_stable28_8.2_nextcloud.log + name: oci_nc_py_api_${{ matrix.server-version }}_8.2_nextcloud.log path: data/nextcloud.log if-no-files-found: warn diff --git a/docs/tech_details/api/occ_command.rst b/docs/tech_details/api/occ_command.rst index 0e5069f2..46e09cb5 100644 --- a/docs/tech_details/api/occ_command.rst +++ b/docs/tech_details/api/occ_command.rst @@ -26,7 +26,7 @@ Params { "name": "appid:unique:command:name", "description": "Description of the command", - "hidden": "true/false", + "hidden": "1/0", "arguments": [ { "name": "argument_name", @@ -66,7 +66,7 @@ Lets assume we have a command `ping` that takes an argument `test_arg` and has a { "name": "my_app_id:ping", "description": "Test ping command", - "hidden": "false", + "hidden": 0, "arguments": [ { "name": "test_arg", diff --git a/lib/Controller/OccCommandController.php b/lib/Controller/OccCommandController.php index d9efa34b..fce56de0 100644 --- a/lib/Controller/OccCommandController.php +++ b/lib/Controller/OccCommandController.php @@ -19,7 +19,7 @@ class OccCommandController extends OCSController { public function __construct( IRequest $request, - private readonly ExAppOccService $service, + private readonly ExAppOccService $service ) { parent::__construct(Application::APP_ID, $request); @@ -33,7 +33,7 @@ public function registerCommand( string $name, string $description, string $execute_handler, - bool $hidden = false, + int $hidden = 0, array $arguments = [], array $options = [], array $usages = [], diff --git a/lib/Db/Console/ExAppOccCommand.php b/lib/Db/Console/ExAppOccCommand.php index 37b245a5..548f62a3 100644 --- a/lib/Db/Console/ExAppOccCommand.php +++ b/lib/Db/Console/ExAppOccCommand.php @@ -15,7 +15,7 @@ * @method string getAppid() * @method string getName() * @method string getDescription() - * @method bool getHidden() + * @method int getHidden() * @method array getArguments() * @method array getOptions() * @method array getUsages() @@ -23,7 +23,7 @@ * @method void setAppid(string $appid) * @method void setName(string $name) * @method void setDescription(string $description) - * @method void setHidden(bool $hidden) + * @method void setHidden(int $hidden) * @method void setArguments(array $arguments) * @method void setOptions(array $options) * @method void setUsages(array $usages) @@ -46,7 +46,7 @@ public function __construct(array $params = []) { $this->addType('appid', 'string'); $this->addType('name', 'string'); $this->addType('description', 'string'); - $this->addType('hidden', 'bool'); + $this->addType('hidden', 'int'); $this->addType('arguments', 'json'); $this->addType('options', 'json'); $this->addType('usages', 'json'); @@ -63,6 +63,8 @@ public function __construct(array $params = []) { } if (isset($params['description'])) { $this->setDescription($params['description']); + } else { + $this->setDescription(''); } if (isset($params['hidden'])) { $this->setHidden($params['hidden']); diff --git a/lib/Db/Console/ExAppOccCommandMapper.php b/lib/Db/Console/ExAppOccCommandMapper.php index b350a55d..527713e4 100644 --- a/lib/Db/Console/ExAppOccCommandMapper.php +++ b/lib/Db/Console/ExAppOccCommandMapper.php @@ -24,7 +24,7 @@ public function findAllEnabled(): array { $qb = $this->db->getQueryBuilder(); $result = $qb->select('exs.*') ->from($this->tableName, 'exs') - ->innerJoin('exs', 'ex_apps', 'exa', 'exa.appid = exs.appid') + ->innerJoin('exs', 'ex_apps', 'exa', $qb->expr()->eq('exa.appid', 'exs.appid')) ->where( $qb->expr()->eq('exa.enabled', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) ) diff --git a/lib/Db/ExAppEventsListenerMapper.php b/lib/Db/ExAppEventsListenerMapper.php index 96e5ce8d..b7ac555c 100644 --- a/lib/Db/ExAppEventsListenerMapper.php +++ b/lib/Db/ExAppEventsListenerMapper.php @@ -26,7 +26,7 @@ public function findAllEnabled(): array { $qb = $this->db->getQueryBuilder(); $result = $qb->select('exs.*') ->from($this->tableName, 'exs') - ->innerJoin('exs', 'ex_apps', 'exa', 'exa.appid = exs.appid') + ->innerJoin('exs', 'ex_apps', 'exa', $qb->expr()->eq('exa.appid', 'exs.appid')) ->where( $qb->expr()->eq('exa.enabled', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) ) diff --git a/lib/Db/SpeechToText/SpeechToTextProviderMapper.php b/lib/Db/SpeechToText/SpeechToTextProviderMapper.php index 3a806b70..048722cc 100644 --- a/lib/Db/SpeechToText/SpeechToTextProviderMapper.php +++ b/lib/Db/SpeechToText/SpeechToTextProviderMapper.php @@ -26,7 +26,7 @@ public function findAllEnabled(): array { $qb = $this->db->getQueryBuilder(); $result = $qb->select('exs.*') ->from($this->tableName, 'exs') - ->innerJoin('exs', 'ex_apps', 'exa', 'exa.appid = exs.appid') + ->innerJoin('exs', 'ex_apps', 'exa', $qb->expr()->eq('exa.appid', 'exs.appid')) ->where( $qb->expr()->eq('exa.enabled', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) ) diff --git a/lib/Db/TextProcessing/TextProcessingProviderMapper.php b/lib/Db/TextProcessing/TextProcessingProviderMapper.php index 21155a3a..10fe1935 100644 --- a/lib/Db/TextProcessing/TextProcessingProviderMapper.php +++ b/lib/Db/TextProcessing/TextProcessingProviderMapper.php @@ -26,7 +26,7 @@ public function findAllEnabled(): array { $qb = $this->db->getQueryBuilder(); $result = $qb->select('exs.*') ->from($this->tableName, 'exs') - ->innerJoin('exs', 'ex_apps', 'exa', 'exa.appid = exs.appid') + ->innerJoin('exs', 'ex_apps', 'exa', $qb->expr()->eq('exa.appid', 'exs.appid')) ->where( $qb->expr()->eq('exa.enabled', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) )->executeQuery(); diff --git a/lib/Db/Translation/TranslationProvider.php b/lib/Db/Translation/TranslationProvider.php index cf55f5ce..fe149a52 100644 --- a/lib/Db/Translation/TranslationProvider.php +++ b/lib/Db/Translation/TranslationProvider.php @@ -67,6 +67,8 @@ public function __construct(array $params = []) { } if (isset($params['action_detect_lang'])) { $this->setActionDetectLang($params['action_detect_lang']); + } else { + $this->setActionDetectLang(''); } } diff --git a/lib/Db/Translation/TranslationProviderMapper.php b/lib/Db/Translation/TranslationProviderMapper.php index 9a791f6a..a05b443e 100644 --- a/lib/Db/Translation/TranslationProviderMapper.php +++ b/lib/Db/Translation/TranslationProviderMapper.php @@ -26,7 +26,7 @@ public function findAllEnabled(): array { $qb = $this->db->getQueryBuilder(); $result = $qb->select('exs.*') ->from($this->tableName, 'exs') - ->innerJoin('exs', 'ex_apps', 'exa', 'exa.appid = exs.appid') + ->innerJoin('exs', 'ex_apps', 'exa', $qb->expr()->eq('exa.appid', 'exs.appid')) ->where( $qb->expr()->eq('exa.enabled', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) ) diff --git a/lib/Db/UI/FilesActionsMenuMapper.php b/lib/Db/UI/FilesActionsMenuMapper.php index dceee2c1..fc394d1b 100644 --- a/lib/Db/UI/FilesActionsMenuMapper.php +++ b/lib/Db/UI/FilesActionsMenuMapper.php @@ -26,7 +26,7 @@ public function findAllEnabled(): array { $qb = $this->db->getQueryBuilder(); $result = $qb->select('exs.*') ->from($this->tableName, 'exs') - ->innerJoin('exs', 'ex_apps', 'exa', 'exa.appid = exs.appid') + ->innerJoin('exs', 'ex_apps', 'exa', $qb->expr()->eq('exa.appid', 'exs.appid')) ->where( $qb->expr()->eq('exa.enabled', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) ) diff --git a/lib/Db/UI/SettingsFormMapper.php b/lib/Db/UI/SettingsFormMapper.php index ba9647f2..3008f46b 100644 --- a/lib/Db/UI/SettingsFormMapper.php +++ b/lib/Db/UI/SettingsFormMapper.php @@ -26,7 +26,7 @@ public function findAllEnabled(): array { $qb = $this->db->getQueryBuilder(); $result = $qb->select('exs.*') ->from($this->tableName, 'exs') - ->innerJoin('exs', 'ex_apps', 'exa', 'exa.appid = exs.appid') + ->innerJoin('exs', 'ex_apps', 'exa', $qb->expr()->eq('exa.appid', 'exs.appid')) ->where( $qb->expr()->eq('exa.enabled', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) ) diff --git a/lib/Db/UI/TopMenuMapper.php b/lib/Db/UI/TopMenuMapper.php index 813b8af8..6d4a85bb 100644 --- a/lib/Db/UI/TopMenuMapper.php +++ b/lib/Db/UI/TopMenuMapper.php @@ -26,7 +26,7 @@ public function findAllEnabled(): array { $qb = $this->db->getQueryBuilder(); $result = $qb->select('exs.*') ->from($this->tableName, 'exs') - ->innerJoin('exs', 'ex_apps', 'exa', 'exa.appid = exs.appid') + ->innerJoin('exs', 'ex_apps', 'exa', $qb->expr()->eq('exa.appid', 'exs.appid')) ->where( $qb->expr()->eq('exa.enabled', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) ) diff --git a/lib/Fetcher/ExAppArchiveFetcher.php b/lib/Fetcher/ExAppArchiveFetcher.php index 9d2dd986..6045e3e9 100644 --- a/lib/Fetcher/ExAppArchiveFetcher.php +++ b/lib/Fetcher/ExAppArchiveFetcher.php @@ -46,9 +46,7 @@ public function downloadInfoXml(array $exAppAppstoreData, string &$extractedDir) // Validate signature of downloaded archive $certificate = openssl_get_publickey($exAppAppstoreData['certificate']); - $verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($releaseSignature), $certificate, OPENSSL_ALGO_SHA512); - - if (!$verified) { + if (openssl_verify(file_get_contents($tempFile), base64_decode($releaseSignature), $certificate, OPENSSL_ALGO_SHA512) !== 1) { return null; } diff --git a/lib/Migration/Version2205Date20240411124836.php b/lib/Migration/Version2205Date20240411124836.php index 492fbee8..af120e83 100644 --- a/lib/Migration/Version2205Date20240411124836.php +++ b/lib/Migration/Version2205Date20240411124836.php @@ -36,7 +36,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt // Symfony\Component\Console\Command\Command->setName() $table->addColumn('name', Types::STRING, [ 'notnull' => true, - 'length' => 128, + 'length' => 64, ]); // Symfony\Component\Console\Command\Command->setDescription() $table->addColumn('description', Types::STRING, [ @@ -46,6 +46,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt // Symfony\Component\Console\Command\Command->setHidden() $table->addColumn('hidden', Types::SMALLINT, [ 'notnull' => true, + 'default' => 0, + 'length' => 1, ]); // Symfony\Component\Console\Command\Command->addArgument() $table->addColumn('arguments', Types::JSON, [ diff --git a/lib/Service/ExAppOccService.php b/lib/Service/ExAppOccService.php index 261d82da..ec23da9a 100644 --- a/lib/Service/ExAppOccService.php +++ b/lib/Service/ExAppOccService.php @@ -36,7 +36,7 @@ public function registerCommand( string $appId, string $name, string $description, - bool $hidden, + int $hidden, array $arguments, array $options, array $usages, @@ -124,7 +124,7 @@ public function __construct( protected function configure() { $this->setName($this->occCommand->getName()); $this->setDescription($this->occCommand->getDescription()); - $this->setHidden($this->occCommand->getHidden()); + $this->setHidden(filter_var($this->occCommand->getHidden(), FILTER_VALIDATE_BOOLEAN)); foreach ($this->occCommand->getArguments() as $argument) { $this->addArgument( $argument['name'],