<?php declare(strict_types=1);

namespace Plugin\css_vatSelect\Migrations;

use JTL\Helpers\Text;
use JTL\Plugin\PluginInterface;
use JTL\Shop;
use JTL\Mail\Mail\Mail;
use JTL\Mail\Mailer;


use JTL\Plugin\Migration;
use JTL\Update\IMigration;

/**
 * Class Migration20211021123301
 * @package Plugin\jtl_test\Migrations
 */
class Migration20211021123301 extends Migration implements IMigration   {
    /**
     * @inheritdoc
     */

    public function copyTable($sourceDB,$destinationDB="", $copyTable=true,$deleteSourceDB=false) {
        error_log('starte copy '.$sourceDB);
        $result = $this->getDB()->query("SHOW TABLES LIKE '".$sourceDB."'",2);
        if($copyTable && $result !== null && is_array($result) && count($result)) {
            error_log('DB Vorhanden '.$sourceDB);
            $result = $this->getDB()->query("SELECT * FROM ".$sourceDB." WHERE 1",2);
            foreach($result as $oItem) {
                error_log('schreibe Datensatz nach '.$destinationDB);
                $this->getDB()->insert($destinationDB,$oItem);
            }
        }
        if($deleteSourceDB) {
            $this->execute("DROP TABLE IF EXISTS ".$sourceDB,3);
        }
    }



    public function up()    {
            $this->execute("UPDATE css_vatSelectConfig set `version` = '2.2.0' ");
    }

    /**
     * @inheritdoc
     */
    public function down() {
        if ($this->doDeleteData()) {
        }
    }
}
