<commit_before><?php
/**
 * Add a new column (maxNumberOfItems) to Playlist table
 *
 * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
 */

use Phinx\Migration\AbstractMigration;

class AddNumberOfItemsToPlaylistMigration extends AbstractMigration
{
    /** @inheritDoc */
    public function change()
    {
        $this->table('playlist')
            ->addColumn('maxNumberOfItems', 'integer', ['default' => null, 'null' => true, 'after' => 'filterMediaTags'])
            ->save();

        $this->table('setting')->insert([
            [
                'setting' => 'DEFAULT_DYNAMIC_PLAYLIST_MAXNUMBER',
                'value' => 30,
                'userSee' => 1,
                'userChange' => 1
            ],
            [
                'setting' => 'DEFAULT_DYNAMIC_PLAYLIST_MAXNUMBER_LIMIT',
                'value' => 100,
                'userSee' => 1,
                'userChange' => 1
            ]
        ])->save();

        $this->execute('UPDATE `playlist` SET maxNumberOfItems = 30 WHERE isDynamic = 1');
    }
}<commit_msg>Playlist max number of items migration adjustments<commit_after><?php
/**
 * Add a new column (maxNumberOfItems) to Playlist table
 * Add two new Settings for default and limit of items per dynamic Playlist
 * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
 */

use Phinx\Migration\AbstractMigration;

class AddNumberOfItemsToPlaylistMigration extends AbstractMigration
{
    /** @inheritDoc */
    public function change()
    {
        // add a new column to the Playlist table
        $this->table('playlist')
            ->addColumn('maxNumberOfItems', 'integer', ['default' => null, 'null' => true, 'after' => 'filterMediaTags'])
            ->save();

        // get the count of Widgets in dynamic Playlists, first element will be the highest
        $widgetCount = $this->query('
                SELECT COUNT(*) AS cnt, widget.playlistId
                    FROM `widget` 
                    WHERE playlistId IN (SELECT playlistId FROM `playlist` WHERE isDynamic = 1)
                GROUP BY widget.playlistId
                ORDER BY COUNT(*) DESC
        ');
        $widgetCountData = $widgetCount->fetchAll(PDO::FETCH_ASSOC);

        // compare our proposed default values with the highest Widget count on dynamic Playlist in the system
        $default = max($widgetCountData[0]['cnt'], 30);
        $max = max($widgetCountData[0]['cnt'], 100);

        // set all dynamic Playlists maxNumberOfItems to the default value
        $this->execute('UPDATE `playlist` SET maxNumberOfItems = ' . $default. ' WHERE isDynamic = 1');

        // insert new Settings with default and max values calculated above
        $this->table('setting')->insert([
            [
                'setting' => 'DEFAULT_DYNAMIC_PLAYLIST_MAXNUMBER',
                'value' => $default,
                'userSee' => 1,
                'userChange' => 1
            ],
            [
                'setting' => 'DEFAULT_DYNAMIC_PLAYLIST_MAXNUMBER_LIMIT',
                'value' => $max,
                'userSee' => 1,
                'userChange' => 1
            ]
        ])->save();
    }
}
{'fraction_non_alphanumeric': 0.12125039469529524, 'fraction_numerical': 0.008525418377012947, 'mean_word_length': 2.09375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3874735', 'n_tokens_mistral': 888, 'n_tokens_neox': 837, 'n_words': 224}