<?php
namespace App\Shell;
use Cake\Console\Shell;
use Cake\ORM\TableRegistry;
use Cake\Auth\DefaultPasswordHasher;
use Cake\Datasource\ConnectionManager;
use Cake\Filesystem\Folder;
use Cake\Filesystem\File;
/**
* DropShell Class.
*
* ShellClass of cake shell command 'drop'.
* Drop all application tables for development.
*
* @access public
* @author hyano@ampware.jp
* @category Batch processing
* @package Shell
*/
class DropShell extends Shell
{
/**
* Initialize instance for all methods.
* @param void
* @return void
*/
public function initialize() {
parent::initialize();
$this->Hasher = new DefaultPasswordHasher();
$this->Connection = ConnectionManager::get('default');
}
/**
* Printing welcome messages.
* @param void
* @return void
*/
public function startup() {
// If you want to output welcome messages, override parent method like this.
// parent::initialize();
}
/**
* Main command for `$ bin/cake example`.
* Method runs when executed without sub-command or args.
* @param void
* @return void
*/
public function main() {
$isContinue = $this->in('Want to continue the process ?', ['y', 'N'], 'N');
if ($isContinue !== 'y') $this->abort('Process was canceled.');
if (empty($this->Connection)) $this->abort('Fatal: Missing DB connection.');
$tables = $this->Connection->schemaCollection()->listTables();
$tables = implode(', ', $tables);
$this->Connection->query('SET FOREIGN_KEY_CHECKS=0');
$this->Connection->query('DROP TABLE '.$tables);
$this->Connection->query('SET FOREIGN_KEY_CHECKS=1');
$this->out('success!');
}
}