Skip to content

Commit

Permalink
Query Music app class from the \OC::$server instead of creating directly
Browse files Browse the repository at this point in the history
This prevents error log spamming on NC18+ when the debug mode has been
enabled with `'debug' => true` and PHP version older than 7.4 is used.
Probably this also might have a positive performance impact.

refs #849
  • Loading branch information
paulijar committed May 6, 2021
1 parent 76399da commit 34da573
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use \OCP\AppFramework\IAppContainer;

$app = new Music();
$app = \OC::$server->query(Music::class);

$c = $app->getContainer();
$appName = $c->query('AppName');
Expand Down Expand Up @@ -55,7 +55,7 @@
);

/**
* Set content security policy to allow streaming media from the configured external sources if we have a logged-in user
* Set content security policy to allow streaming media from the configured external sources
*/
function adjustCsp(IAppContainer $container) {
/** @var \OCP\IConfig $config */
Expand Down
4 changes: 2 additions & 2 deletions appinfo/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
* @author Pauli Järvinen <[email protected]>
* @copyright Leizh 2014
* @copyright Morris Jobke 2014
* @copyright Pauli Järvinen 2017
* @copyright Pauli Järvinen 2017 - 2021
*/

use \OCA\Music\App\Music;

$app = new Music();
$app = \OC::$server->query(Music::class);
$c = $app->getContainer();

$application->add(new OCA\Music\Command\Scan(
Expand Down
4 changes: 2 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
* @author Morris Jobke <[email protected]>
* @author Pauli Järvinen <[email protected]>
* @copyright Morris Jobke 2014
* @copyright Pauli Järvinen 2017 - 2020
* @copyright Pauli Järvinen 2017 - 2021
*/

namespace OCA\Music;

use \OCA\Music\App\Music;

$app = new Music();
$app = \OC::$server->query(Music::class);

$app->registerRoutes($this, ['routes' => [
// page
Expand Down
4 changes: 3 additions & 1 deletion lib/Backgroundjob/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* later. See the COPYING file.
*
* @author Morris Jobke <[email protected]>
* @author Pauli Järvinen <[email protected]>
* @copyright Morris Jobke 2013, 2014
* @copyright Pauli Järvinen 2017 - 2021
*/

namespace OCA\Music\Backgroundjob;
Expand All @@ -20,7 +22,7 @@ class Cleanup {
* Run background cleanup task
*/
public static function run() {
$app = new Music();
$app = \OC::$server->query(Music::class);

$container = $app->getContainer();

Expand Down
6 changes: 3 additions & 3 deletions lib/Hooks/FileHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Morris Jobke <[email protected]>
* @author Pauli Järvinen <[email protected]>
* @copyright Morris Jobke 2014
* @copyright Pauli Järvinen 2017 - 2020
* @copyright Pauli Järvinen 2017 - 2021
*/

namespace OCA\Music\Hooks;
Expand All @@ -32,7 +32,7 @@ public function __construct($filesystemRoot) {
* @param Node $node pointing to the file or folder
*/
public static function deleted(Node $node) {
$app = new Music();
$app = \OC::$server->query(Music::class);
$container = $app->getContainer();
$scanner = $container->query('Scanner');

Expand All @@ -56,7 +56,7 @@ public static function updated(Node $node) {
// File::fopen, this hook gets triggered immediately after the opening succeeds,
// before anything is actually written and while the file is *exlusively locked
// because of the write mode*. See #638.
$app = new Music();
$app = \OC::$server->query(Music::class);
$container = $app->getContainer();
try {
self::handleUpdated($node, $container);
Expand Down
8 changes: 4 additions & 4 deletions lib/Hooks/ShareHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Morris Jobke <[email protected]>
* @author Pauli Järvinen <[email protected]>
* @copyright Morris Jobke 2014
* @copyright Pauli Järvinen 2017 - 2020
* @copyright Pauli Järvinen 2017 - 2021
*/

namespace OCA\Music\Hooks;
Expand Down Expand Up @@ -38,7 +38,7 @@ private static function removeSharedItem($app, $itemType, $nodeId, $owner, $remo
*/
public static function itemUnshared(array $params) {
$shareType = $params['shareType'];
$app = new Music();
$app = \OC::$server->query(Music::class);

// react only on user and group shares
if ($shareType == \OCP\Share::SHARE_TYPE_USER) {
Expand All @@ -63,7 +63,7 @@ public static function itemUnshared(array $params) {
public static function itemUnsharedFromSelf(array $params) {
// The share recipient may be an individual user or a group, but the item is always removed from
// the current user alone.
$app = new Music();
$app = \OC::$server->query(Music::class);
$removeFromUsers = [ $app->getContainer()->query('UserId') ];

self::removeSharedItem($app, $params['itemType'], $params['itemSource'], $params['uidOwner'], $removeFromUsers);
Expand All @@ -79,7 +79,7 @@ public static function itemShared(array $params) {
// user will be prompted to update database the next time she opens the Music app.
// Similarly, do not auto-update on group shares.
if ($params['itemType'] === 'file' && $params['shareType'] == \OCP\Share::SHARE_TYPE_USER) {
$app = new Music();
$app = \OC::$server->query(Music::class);
$container = $app->getContainer();
$scanner = $container->query('Scanner');
$sharerFolder = $container->query('UserFolder');
Expand Down
4 changes: 2 additions & 2 deletions lib/Search/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Pauli Järvinen <[email protected]>
* @copyright Morris Jobke 2013, 2014
* @copyright Leizh 2014
* @copyright Pauli Järvinen 2018 - 2020
* @copyright Pauli Järvinen 2018 - 2021
*/

namespace OCA\Music\Search;
Expand All @@ -38,7 +38,7 @@ class Provider extends \OCP\Search\Provider {
private $logger;

public function __construct() {
$app = new Music();
$app = \OC::$server->query(Music::class);
$c = $app->getContainer();

$this->artistMapper = $c->query('ArtistMapper');
Expand Down

0 comments on commit 34da573

Please sign in to comment.