ampache / ampache

A web based audio/video streaming application and file manager allowing you to access your music & videos from anywhere, using almost any internet enabled device.
http://ampache.org
GNU Affero General Public License v3.0
3.52k stars 588 forks source link

Crash during catalog update: Uninitialized Typed property in Tag.php #3965

Open gurota opened 4 months ago

gurota commented 4 months ago

Description

Crash during catalog update: Uninitialized Typed property in Tag.php

Describe the bug

During catalog update (and elsewhere, where this code is called) a crash occurs due to a class property being accessed without prior initialization:

function/method: public static function add_tag_map($type, $object_id, $tag_id, $user = true)

line 428: if (!$parent->is_hidden) {

file: src/Repository/Model/Tag.php

To reproduce

Expected behavior

Environment

Client type

Logs

sudo -u http bin/cli run:updateCatalog -ceag Reading Catalog: "Music"

Start cleaning orphaned media entries


Start adding new media Error Typed property Ampache\Repository\Model\Tag::$is_hidden must not be accessed before initialization (thrown in /usr/share/webapps/ampache/src/Repository/Model/Tag.php:421)

Stack Trace:

0) Ampache\Repository\Model\Tag::add_tag_map() at /usr/share/webapps/ampache/src/Repository/Model/Tag.php:216 1) Ampache\Repository\Model\Tag::add() at /usr/share/webapps/ampache/src/Repository/Model/Song.php:422 2) Ampache\Repository\Model\Song::insert() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:945 3) Ampache\Module\Catalog\Catalog_local->_insert_local_song() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:447 4) Ampache\Module\Catalog\Catalog_local->add_file() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:308 5) Ampache\Module\Catalog\Catalog_local->add_files() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:365 6) Ampache\Module\Catalog\Catalog_local->add_file() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:308 7) Ampache\Module\Catalog\Catalog_local->add_files() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:365 8) Ampache\Module\Catalog\Catalog_local->add_file() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:308 9) Ampache\Module\Catalog\Catalog_local->add_files() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:365 10) Ampache\Module\Catalog\Catalog_local->add_file() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:308 11) Ampache\Module\Catalog\Catalog_local->add_files() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:365 12) Ampache\Module\Catalog\Catalog_local->add_file() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:308 13) Ampache\Module\Catalog\Catalog_local->add_files() at /usr/share/webapps/ampache/src/Module/Catalog/Catalog_local.php:531 14) Ampache\Module\Catalog\Catalog_local->add_to_catalog() at /usr/share/webapps/ampache/src/Module/Catalog/Update/UpdateCatalog.php:162 15) Ampache\Module\Catalog\Update\UpdateCatalog->update() at /usr/share/webapps/ampache/src/Module/Cli/UpdateCatalogCommand.php:84 16) Ampache\Module\Cli\UpdateCatalogCommand->execute() at /usr/share/webapps/ampache/vendor/adhocore/cli/src/Application.php:366 17) Ahc\Cli\Application->doAction() at /usr/share/webapps/ampache/vendor/adhocore/cli/src/Application.php:280 18) Ahc\Cli\Application->handle() at /usr/share/webapps/ampache/bin/cli:82

Possible Fix

Set default value to property "is_hidden" in class "Tag":

Line 46 / Tag.php: public int $is_hidden = 0;

I don't know what is_hidden is supposed to do, but a quick fix - as shown above - seems to work.

lachlan-00 commented 3 months ago

I'll have a dig.

Going from Tag::add to Tag::add_tag_map might mean that it's freshly created and not initialised as a value.

setting to 0 is probably good enough as by default a tag isn't hidden but i'll see if there's any bug causing it.

We use hidden to basically just hide crap tags. I actually get an error on the tag pages for something so there must be something up.

image

Hidden = never show the tag

retag is where you change this tag into something else

e.g Alt. Rock I re-tag into Alternative rock.

when you tick persistent this will hide "alt. rock" and rename the tag to "alternative rock" for every linked item

Keep existing means you can add a tag and keep both tags. This can be good when you want to tag a tag with a common alternative. Female vocal can retag to vocal and then keep existing.

that way you can tag male vocal and female vocal to just one tag and keep the original tags.

Hope that helps explain it and i'll look for the bug now

lachlan-00 commented 3 months ago

set your change with 0b3ff7ba3f722c68a6a3fa15d04edd3a370038a9 i must not have had any new tags to break it but i think defining the default property value to 0 is the way to do it.

gurota commented 3 months ago

Thank you for the explanation and quick fix/commit! Quite elaborate tagging mechanism ... Setting the default to 0 still works for me and did not stumble on a medium-large library.