Skip to content

Commit

Permalink
Fix the background jobs not working on NC29+
Browse files Browse the repository at this point in the history
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
nextcloud/server#42291 which has made a
come-back, after being already fixed in NC28.0.2. [sigh]

refs #1132
  • Loading branch information
paulijar committed Mar 28, 2024
1 parent 697990b commit 23be47a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [Unreleased]

### Added
- Support for Nextcloud 29
[#1132](https://github.com/owncloud/music/issues/1132)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependencies>
<php min-version="7.1" max-version="8.3"/>
<owncloud min-version="10" max-version="10" />
<nextcloud min-version="13" max-version="28" />
<nextcloud min-version="13" max-version="29" />
</dependencies>
<types>
<!-- update metadata cache when create/update/delete a file -->
Expand Down
16 changes: 14 additions & 2 deletions lib/App/Music.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Pauli Järvinen <pauli.jarvinen@gmail.com>
* @copyright Morris Jobke 2014
* @copyright Pauli Järvinen 2017 - 2023
* @copyright Pauli Järvinen 2017 - 2024
*/

namespace OCA\Music\App;
Expand Down Expand Up @@ -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();

/**
Expand Down
8 changes: 2 additions & 6 deletions lib/BackgroundJob/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Pauli Järvinen <pauli.jarvinen@gmail.com>
* @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 {

/**
Expand Down
8 changes: 2 additions & 6 deletions lib/BackgroundJob/PodcastUpdateCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@
* later. See the COPYING file.
*
* @author Pauli Järvinen <pauli.jarvinen@gmail.com>
* @copyright Pauli Järvinen 2021 - 2023
* @copyright Pauli Järvinen 2021 - 2024
*/

namespace OCA\Music\BackgroundJob;

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 {

/**
Expand Down
7 changes: 6 additions & 1 deletion phpstan-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
\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');
8 changes: 8 additions & 0 deletions stubs/OCP/BackgroundJob/TimedJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace OCP\BackgroundJob;

/**
* This stub exists to make Scrutinizer happy.
*/
abstract class TimedJob extends \OC\BackgroundJob\TimedJob {
}

0 comments on commit 23be47a

Please sign in to comment.