View file Gift/migrations/20190323162111_seed_to_gifts.php

File size: 633B
<?php

use Phinx\Migration\AbstractMigration;

class SeedToGifts extends AbstractMigration
{
    /**
     * Migrate Up.
     */
    public function up(): void
    {
        $gifts = array_map('basename', glob(MODULES . '/Gift/resources/assets/*.{gif,png,jpg,jpeg}', GLOB_BRACE));

        foreach ($gifts as $gift) {
            $this->execute("INSERT INTO gifts (path, price, created_at) VALUES ('/assets/modules/gifts/" . $gift . "', " . (mt_rand(1, 10) * 100) . ", " . SITETIME . ");");
        }
    }

    /**
     * Migrate Down.
     */
    public function down(): void
    {
        $this->execute('TRUNCATE gifts');
    }
}