Overload Migration seed template


#1

Hi,

I tried to overload the bake template for seed migration command.
My objective is to obtain this :

        <?php
        use Migrations\AbstractSeed;

        /**
         * Table seed.
         */
        class TableSeed extends AbstractSeed
        {
            /**
             * Run Method.
            ...
             */
            public function run()
            {
                $data = [
                    table data
                ];

                $table = $this->table('table');
                $this->execute('SET foreign_key_checks=0');
                $this->execute('TRUNCATE TABLE ' . $table->getName());
                $table->insert($data)->save();
                $this->execute('SET foreign_key_checks=1');
            }
        }

Instead of the actual template :

     <?php
    use Migrations\AbstractSeed;

    /**
     * Table seed.
     */
    class TableSeed extends AbstractSeed
    {
        /**
         * Run Method.
         ...
         */
        public function run()
        {
            $data = [
                table data
            ];

            $table = $this->table('table');
            $table->insert($data)->save();
        }
    }

I follow the documentation here

So I copied the seed.ctp file into my App/src/Template/Bake/Seed/ folder.
I modified it to this :

    <%
    /**
     [License]
     */
    %>
    <?php
    use Migrations\AbstractSeed;

    /**
     * <%= $name %> seed.
     */
    class <%= $name %>Seed extends AbstractSeed
    {
        /**
         * Run Method.
         ...
         */
        public function run()
        {
    <% if ($records): %>
            $data = <%= $records %>;
    <% else: %>
            $data = [];
    <% endif; %>
            
            $table = $this->table('<%= $table %>');
            $this->execute('SET foreign_key_checks=0');
            $this->execute('TRUNCATE TABLE ' . $table->getName());
            $table->insert($data)->save();
            $this->execute('SET foreign_key_checks=1');
        }
    }

But the command bin\cake bake seed --data Table
doesn’t change anything, I obtain the default file.

So I create a plugin named Test with Bake.
I put my file seed.ctp into the folder plugins/Test/src/Template/Bake/Seed/

But the command bin\cake bake seed --data --theme Test Table
doesn’t change anything too.

Am I doing something wrong ?
I tried to read the bake code but I clearly don’t understand how the bake template works.

I am using cakephp v3.3.15

Thanks for your help.