Exemplo n.º 1
0
 function createTables()
 {
     /// check if database exists and filled-in
     $this->db->query("SET NAMES utf8");
     $this->db->query("SET character_set_database=utf8");
     $this->db->query("SET character_set_server=utf8");
     $xml = new Am_DbSync();
     foreach ($this->dbXmlFiles as $fn) {
         $xmlFile = file_get_contents($fn);
         if (!strlen($xmlFile)) {
             throw new Am_Setup_Exception("Could not read XML file [{$fn}] - file does not exists or empty");
         }
         foreach ($this->config as $k => $v) {
             if ($k == self::ADMIN_PASS) {
                 $ph = new PasswordHash(12, true);
                 $xmlFile = str_replace($k, $this->db->quote($ph->HashPassword($v)), $xmlFile);
             } elseif ($k[0] == '@') {
                 $xmlFile = str_replace($k, $this->db->quote($v), $xmlFile);
             }
         }
         $xml->parseXml($xmlFile);
     }
     $db = new Am_DbSync();
     $db->parseTables($this->db);
     $diff = $xml->diff($db);
     $diff->apply($this->db);
 }
Exemplo n.º 2
0
 /**
  * @return Am_DbSync_Diff
  */
 public function diff(Am_DbSync $compareTo)
 {
     $diff = new Am_DbSync_Diff();
     $diff->compareArrays($this->getTables(), $compareTo->getTables());
     foreach ($this->dropTables as $tableName) {
         if ($compareTo->getTable($tableName)) {
             $diff->addDropConfirmed(new Am_DbSync_Table($tableName));
         }
     }
     return $diff;
 }
Exemplo n.º 3
0
 function dbSync($reportNoChanges = true, $modules = null)
 {
     $nl = empty($_SERVER['REMOTE_ADDR']) ? "\n" : "<br />\n";
     $db = new Am_DbSync();
     $db->parseTables($this->di->db);
     $xml = new Am_DbSync();
     $xml->parseXml(file_get_contents(APPLICATION_PATH . '/default/db.xml'));
     if ($modules === null) {
         $modules = $this->di->modules->getEnabled();
     }
     foreach ($modules as $module) {
         if (file_exists($file = APPLICATION_PATH . '/' . $module . "/db.xml")) {
             print "Parsing XML file: [application/{$module}/db.xml]{$nl}";
             $xml->parseXml(file_get_contents($file));
         }
     }
     $this->di->hook->call(Am_Event::DB_SYNC, array('dbsync' => $xml));
     $diff = $xml->diff($db);
     if ($sql = $diff->getSql($this->di->db->getPrefix())) {
         print "Doing the following database structure changes:{$nl}";
         print $diff->render();
         print "{$nl}";
         ob_end_flush();
         $diff->apply($this->di->db);
         print "DONE{$nl}";
         ob_end_flush();
     } elseif ($reportNoChanges) {
         print "No database structure changes required{$nl}";
     }
     $this->etSync($modules);
     $this->di->store->set('db_version', AM_VERSION);
 }