Page 1 of 1

Create setup task

Posted: 12 Jan 2018, 13:08
by Travin
Hey
I'm creating new Setup Task according to https://aimeos.org/docs/Developers/Library/Setup_tasks/.
First of all, I created ext\my-ext\lib\custom\setup\SubscriptionAddTables.php:

Code: Select all

<?php
namespace Aimeos\MW\Setup\Task;

class SubscriptionAddTables extends TablesCreateMShop
{
    /**
     * Returns the list of task names which this task depends on.
     *
     * @return string[] List of task names
     */
    public function getPreDependencies()
    {
        return array( 'TablesCreateMShop' );
    }

    /**
     * Returns the list of task names which depends on this task.
     *
     * @return string[] List of task names
     */
    public function getPostDependencies()
    {
    }

    /**
     * Updates the schema and migrates the data
     */
    public function migrate()
    {

        $this->msg( 'Creating SUBSCRIPTIONS tables', 0 );
        $this->status( '' );
        //die;
        $ds = DIRECTORY_SEPARATOR;
        $files = array( 'db-product' => __DIR__ . $ds . 'default' . $ds . 'schema' . $ds . 'subscription.php' );

        $this->setupSchema( $files );
    }

    /**
     * Undo all schema changes and migrate data back
     */
    public function rollback()
    {
    }

    /**
     * Cleans up old data required for roll back
     */
    public function clean()
    {
    }
}
Then, i created ext\my-ext\lib\custom\setup\default\schema\subscription.php

Code: Select all

<?php
return array(
    'table' => array(
        'mshop_subscription' => function ( \Doctrine\DBAL\Schema\Schema $schema ) {

            $table = $schema->createTable( 'mshop_subscription' );

            $table->addColumn( 'id', 'integer', array( 'autoincrement' => true ) );
            $table->addColumn( 'siteid', 'integer', array() );
            $table->addColumn( 'myvalue', 'string', array( 'length' => 255, 'notnull' => false ) );
            $table->addColumn( 'mtime', 'datetime', array() );
            $table->addColumn( 'ctime', 'datetime', array() );
            $table->addColumn( 'editor', 'string', array( 'length' => 255 ) );

            //$table->setPrimaryKey( array( 'id' ), 'pk_msattmy_id' );
            //$table->addUniqueIndex( array( 'siteid', 'myvalue' ), 'unq_msattmy_sid_myval' );

            return $schema;
        },
    ),
);
Finally, i run artisan aimeos:setup

The result is:

Code: Select all

Creating SUBSCRIPTIONS tables
  Using tables from subscription.php
But there are no one new table at db. :(
What did I forget to do?
Thanks

Re: Create setup task

Posted: 12 Jan 2018, 18:24
by aimeos
Hm, everything looks fine. Can you add some debug statements to the TablesCreateMShop class to see why no table is created? https://github.com/aimeos/aimeos-core/b ... p.php#L164