XF 2.2 setup, add columns

Robert9

Well-known member
I've run out of ideas. May someone knows what is wrong here?
I cant add my three columns to post, thread, forum.
I have no error.
I have checked permissions of mysql user
Is there anything else I have to do to make setup running?

Code:
<?php

namespace Robert9\Werte;

use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;
use XF\Db\Schema\Alter;

class Setup extends AbstractSetup
{
    use StepRunnerInstallTrait;
    use StepRunnerUpgradeTrait;
    use StepRunnerUninstallTrait;


    public function installStep1()
    {
        $sm = $this->schemaManager();

        foreach ($this->getTables() as $tableName => $callback)
        {
            $sm->createTable($tableName, $callback);
        }
    }

    public function installStep2()
    {
        $sm = $this->schemaManager();

        foreach ($this->getAlters() as $table => $schema)
        {
            if ($sm->tableExists($table))
            {
                $sm->alterTable($table, $schema);
            }
        }
    }

    public function uninstallStep1()
    {
        $sm = $this->schemaManager();

        foreach (array_keys($this->getTables()) as $tableName)
        {
            $sm->dropTable($tableName);
        }
    }

    public function uninstallStep2()
    {
        $sm = $this->schemaManager();
        foreach ($this->getReverseAlters() as $table => $schema)
        {
            if ($sm->tableExists($table))
            {
                $sm->alterTable($table, $schema);
            }
        }
    }


    // ################################## DATA ###########################################


    protected function getTables(): array
    {
        $tables = [];
        return $tables;
    }

    /**
     * @return array
     */
    protected function getAlters()
    {
        $alters = [];

        $alters['xf_post'] = function (Alter $table) {
            $table->addColumn('werte', 'tinyblob')->nullable()->setDefault(null);
        };

        $alters['xf_thread'] = function (Alter $table) {
            $table->addColumn('werte', 'tinyblob')->nullable()->setDefault(null);
        };

        $alters['xf_forum'] = function (Alter $table) {
            $table->addColumn('werte', 'tinyint')->setDefault(0);
        };

        return $alters;
    }

    protected function getReverseAlters()
    {
        $alters = [];

        $alters['xf_post'] = function (Alter $table) {
            $table->dropColumns(['werte']);
        };

        $alters['xf_thread'] = function (Alter $table) {
            $table->dropColumns(['werte']);
        };

        $alters['xf_forum'] = function (Alter $table) {
            $table->dropColumns(['werte']);
        };

        return $alters;
    }
}
 
Have you tried running the installStep2() manually via the xf-addon:install-step command to test out the step?

Also, if you're upgrading your addon the install steps won't run.
 
Top Bottom