Example #1
0
 /**
  * Factory for install db tables.
  * @param  class Translator
  * @param  callable
  * @return Form
  */
 public function dbTablesFactory($translator, callable $onSuccess)
 {
     $form = $this->forms->create($translator);
     $form->addSubmit('send', 'install.db.tables.send');
     $form->onSuccess[] = function (Form $form) use($onSuccess) {
         // Database tables prefix.
         $prefix = $this->getTablePrefix();
         // Database tables.
         $table = [$prefix . 'nav', $prefix . 'settings', $prefix . 'users'];
         try {
             foreach ($table as $check) {
                 if (!$this->query->isExistTable($check)) {
                     continue;
                 }
             }
             // Table 'nav'
             $this->query->addTable('' . 'CREATE TABLE [' . $table[0] . '](' . '[id] int(11) NOT NULL AUTO_INCREMENT,' . '[link] char(30) NOT NULL,' . '[ico] char(30) NOT NULL,' . '[cs] char(30) NOT NULL,' . 'PRIMARY KEY (id))' . 'ENGINE=MyISAM DEFAULT CHARSET=UTF8');
             $nav = [['id' => NULL, 'link' => ':Admin:Admin:', 'ico' => 'fa fa-desktop', 'cs' => 'Administrace'], ['id' => NULL, 'link' => ':Admin:Settings:', 'ico' => 'fa fa-cog', 'cs' => 'Nastavení webu'], ['id' => NULL, 'link' => ':Web:Web:', 'ico' => 'fa fa-globe', 'cs' => 'Web']];
             foreach ($nav as $rows) {
                 $this->query->addValues($table[0], $rows);
             }
             // Table 'settings'
             $this->query->addTable('' . 'CREATE TABLE [' . $table[1] . '](' . '[name] varchar(100) NOT NULL,' . '[value] varchar(255) NOT NULL)' . 'ENGINE=MyISAM DEFAULT CHARSET=UTF8');
             // Table 'users'
             $this->query->addTable('' . 'CREATE TABLE [' . $table[2] . '](' . '[id] int(11) NOT NULL AUTO_INCREMENT,' . '[realname] varchar(50) NOT NULL,' . '[email] varchar(50) NOT NULL,' . '[password] char(60) NOT NULL,' . 'PRIMARY KEY (id))' . 'ENGINE=MyISAM DEFAULT CHARSET=UTF8');
             // Save the installation step into the cache.
             $this->steps->setToCache(Steps::Step2, rand(1, 9));
         } catch (\Exception $e) {
             if ($e->getCode() == 0) {
                 $form->addError('install.db.table.catch');
             }
             return;
         }
         $onSuccess();
     };
     return $form;
 }