/** * Optimize eduTrac SIS Database. * * ## EXAMPLES * * $ ./etsis db optimize * Success: Database optimization complete. */ public function optimize() { try { $this->pdo = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"]); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->pdo->query('SET CHARACTER SET utf8'); } catch (PDOException $e) { ETSIS_CLI::error(sprintf('"%s"', $e->getMessage())); } ETSIS_CLI::line('Starting optimization process...'); $opt = $this->pdo->query("SHOW TABLES"); foreach ($opt as $r) { opt_notify(new \cli\progress\Bar(' %GTable:%n ' . $r['Tables_in_' . DB_NAME], 1000000)); $this->pdo->query('OPTIMIZE TABLE ' . $r['Tables_in_' . DB_NAME]); } $this->pdo = null; ETSIS_CLI::success('Database optimization complete.'); }
/** * Use this command to update installation. * * ## EXAMPLES * * #Updates a current installation. * $ ./etsis core update */ public function update() { $zip = new ZipArchive(); $current_release = ETSIS_CLI::getCurrentRelease(); $file = 'http://etsis.s3.amazonaws.com/core/1.1/release/' . $current_release . '.zip'; if (version_compare(trim(file_get_contents('RELEASE')), $current_release, '<')) { if (ETSIS_CLI::checkExternalFile($file) == 200) { //Download file to the server opt_notify(new \cli\progress\Bar('Downloading ', 1000000)); ETSIS_CLI::getDownload($current_release . '.zip', $file); //Unzip the file to update opt_notify(new \cli\progress\Bar('Unzipping ', 1000000)); $x = $zip->open($current_release . '.zip'); if ($x === true) { //Extract file in root. $zip->extractTo(realpath(__DIR__ . '/../../../../../../')); $zip->close(); //Remove download after completion. unlink($current_release . '.zip'); } ETSIS_CLI::line('Core upgrade complete.'); ETSIS_CLI::line('Run the command %G./etsis db migrate%n to check for database updates.'); } else { ETSIS_CLI::line('Update server cannot be reached. Please try again later.'); } } else { ETSIS_CLI::line('No Update'); } }