From 23be47a5a8b31aba63c87769678b6921e77998a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pauli=20J=C3=A4rvinen?= Date: Sun, 17 Mar 2024 23:41:22 +0200 Subject: [PATCH] Fix the background jobs not working on NC29+ The base class OC\BackgroundJob\TimedJob has been removed in NC29 in favor of OCP\BackgorundJob\TimedJob. However, the new alternative is not available on ownCloud and we now need to dynamically select among these two the one which can be found. Also, marked the app now as compatible with NC29 as it seemed to work fine on NC29-RC1. Except for the Nextcloud files dialog issue https://github.com/nextcloud/server/issues/42291 which has made a come-back, after being already fixed in NC28.0.2. [sigh] refs https://github.com/owncloud/music/issues/1132 --- .scrutinizer.yml | 2 +- CHANGELOG.md | 2 ++ appinfo/info.xml | 2 +- lib/App/Music.php | 16 ++++++++++++++-- lib/BackgroundJob/Cleanup.php | 8 ++------ lib/BackgroundJob/PodcastUpdateCheck.php | 8 ++------ phpstan-bootstrap.php | 7 ++++++- stubs/OCP/BackgroundJob/TimedJob.php | 8 ++++++++ 8 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 stubs/OCP/BackgroundJob/TimedJob.php diff --git a/.scrutinizer.yml b/.scrutinizer.yml index ee2055112..3088c4c57 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -5,7 +5,7 @@ imports: filter: excluded_paths: [js/vendor/*, tests/] dependency_paths: - - "vendor/christophwurst/nextcloud/" + - "vendor/nextcloud/ocp" - "vendor/doctrine/dbal/" - "3rdparty/getID3/getid3/" - "stubs/" diff --git a/CHANGELOG.md b/CHANGELOG.md index 73252e105..463b64055 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## [Unreleased] ### Added +- Support for Nextcloud 29 + [#1132](https://github.com/owncloud/music/issues/1132) ### Changed diff --git a/appinfo/info.xml b/appinfo/info.xml index e8f21b03c..a8ebbe872 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -32,7 +32,7 @@ - + diff --git a/lib/App/Music.php b/lib/App/Music.php index 6c3a33a40..c210e2503 100644 --- a/lib/App/Music.php +++ b/lib/App/Music.php @@ -9,7 +9,7 @@ * @author Morris Jobke * @author Pauli Järvinen * @copyright Morris Jobke 2014 - * @copyright Pauli Järvinen 2017 - 2023 + * @copyright Pauli Järvinen 2017 - 2024 */ namespace OCA\Music\App; @@ -83,14 +83,26 @@ public function __construct(array $urlParams=[]) { \mb_internal_encoding('UTF-8'); + // NC26+ no longer ships OCP\AppFramework\Db\Mapper. Create a class alias which refers to this OCP class if available + // or to our own ponyfill if not (created by copying the said class from NC25). if (!\class_exists('OCA\Music\AppFramework\Db\CompatibleMapper')) { - if (\class_exists(\OCP\AppFramework\Db\Mapper::class)) { + if (\class_exists('OCP\AppFramework\Db\Mapper')) { \class_alias(\OCP\AppFramework\Db\Mapper::class, 'OCA\Music\AppFramework\Db\CompatibleMapper'); } else { \class_alias(\OCA\Music\AppFramework\Db\OldNextcloudMapper::class, 'OCA\Music\AppFramework\Db\CompatibleMapper'); } } + // Create a class alias which refers to the TimedJob either from OC or OCP namespace. The OC version is available + // on ownCloud and on Nextcloud versions <29. The OCP version is available on NC15+. + if (!\class_exists('OCA\Music\BackgroundJob\TimedJob')) { + if (\class_exists('OCP\BackgroundJob\TimedJob')) { + \class_alias(\OCP\BackgroundJob\TimedJob::class, 'OCA\Music\BackgroundJob\TimedJob'); + } else { + \class_alias(\OC\BackgroundJob\TimedJob::class, 'OCA\Music\BackgroundJob\TimedJob'); + } + } + $container = $this->getContainer(); /** diff --git a/lib/BackgroundJob/Cleanup.php b/lib/BackgroundJob/Cleanup.php index 9d61ef2d3..c00d17c68 100644 --- a/lib/BackgroundJob/Cleanup.php +++ b/lib/BackgroundJob/Cleanup.php @@ -9,18 +9,14 @@ * @author Morris Jobke * @author Pauli Järvinen * @copyright Morris Jobke 2013, 2014 - * @copyright Pauli Järvinen 2017 - 2023 + * @copyright Pauli Järvinen 2017 - 2024 */ namespace OCA\Music\BackgroundJob; use OCA\Music\App\Music; -use OC\BackgroundJob\TimedJob; -// NC15+ would have TimedJob also as a public class and has deprecated the private class used above. -// However, we can't use this new alternative as it's not available on ownCloud. -// use OCP\BackgroundJob\TimedJob; - +// The base class extended is a class alias created in OCA\Music\App\Music class Cleanup extends TimedJob { /** diff --git a/lib/BackgroundJob/PodcastUpdateCheck.php b/lib/BackgroundJob/PodcastUpdateCheck.php index 232ec63bc..08458ae0e 100644 --- a/lib/BackgroundJob/PodcastUpdateCheck.php +++ b/lib/BackgroundJob/PodcastUpdateCheck.php @@ -7,7 +7,7 @@ * later. See the COPYING file. * * @author Pauli Järvinen - * @copyright Pauli Järvinen 2021 - 2023 + * @copyright Pauli Järvinen 2021 - 2024 */ namespace OCA\Music\BackgroundJob; @@ -15,11 +15,7 @@ use OCA\Music\App\Music; use OCA\Music\Utility\PodcastService; -use OC\BackgroundJob\TimedJob; -// NC15+ would have TimedJob also as a public class and has deprecated the private class used above. -// However, we can't use this new alternative as it's not available on ownCloud. -// use OCP\BackgroundJob\TimedJob; - +// The base class extended is a class alias created in OCA\Music\App\Music class PodcastUpdateCheck extends TimedJob { /** diff --git a/phpstan-bootstrap.php b/phpstan-bootstrap.php index ece36845f..2033a2db9 100644 --- a/phpstan-bootstrap.php +++ b/phpstan-bootstrap.php @@ -5,4 +5,9 @@ * Also, the autoloading of the classes doesn't seem to work yet while this file is being executed. */ require_once('lib/AppFramework/Db/OldNextcloudMapper.php'); -\class_alias(\OCA\Music\AppFramework\Db\OldNextcloudMapper::class, 'OCA\Music\AppFramework\Db\CompatibleMapper'); \ No newline at end of file +\class_alias(\OCA\Music\AppFramework\Db\OldNextcloudMapper::class, 'OCA\Music\AppFramework\Db\CompatibleMapper'); + +require_once('vendor/nextcloud/ocp/OCP/BackgroundJob/IJob.php'); +require_once('stubs/OC/BackgroundJob/Job.php'); +require_once('stubs/OC/BackgroundJob/TimedJob.php'); +\class_alias(\OC\BackgroundJob\TimedJob::class, '\OCA\Music\BackgroundJob\TimedJob'); \ No newline at end of file diff --git a/stubs/OCP/BackgroundJob/TimedJob.php b/stubs/OCP/BackgroundJob/TimedJob.php new file mode 100644 index 000000000..8f5226686 --- /dev/null +++ b/stubs/OCP/BackgroundJob/TimedJob.php @@ -0,0 +1,8 @@ +