Пример #1
0
 public function install_MX()
 {
     $path = realpath(dirname(__FILE__));
     $this->Install_Path = realpath(dirname($path, 1)) . self::DS;
     unset($path);
     $FsConf = $this->Install_Path . 'config.php';
     $FsUnI = $this->Install_Path . 'plugins' . self::DS . 'admin_mexico' . self::DS . 'extras' . self::DS . 'uninstall.xml';
     if (!copy($FsConf, $FsConf . '.bak')) {
         return (bool) false;
     }
     if (is_writable($FsConf)) {
         $strConf = file_get_contents($FsConf);
         if (strpos($strConf, "define('FS_INSTALL_PATH',") === false) {
             $setDef = self::R . '/// Modificación admin_mexico' . self::R . "define('FS_INSTALL_PATH', '" . $this->Install_Path . "');";
             if (!file_put_contents($FsConf, $setDef, FILE_APPEND | LOCK_EX)) {
                 return (bool) false;
             }
         }
         unset($strConf);
         if (file_exists($FsUnI)) {
             unlink($FsUnI);
         }
         $fp = fopen($FsUnI, 'w+');
         fwrite($fp, '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n");
         fwrite($fp, '<files>' . self::R);
         fclose($fp);
         require_once $this->Install_Path . 'base' . self::DS . 'fs_db2.php';
         $db = new fs_db2();
         if ($db->connect()) {
             $tables = $db->list_tables();
             file_put_contents($FsUnI, '<databases>' . self::R, FILE_APPEND | LOCK_EX);
             $qry = "SELECT TABLE_NAME AS name FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . FS_DB_NAME . "' AND COLUMN_NAME = 'codpostal' AND TABLE_NAME='empresa';";
             if ($rs = $db->select($qry)) {
                 foreach ($rs as $tb) {
                     $e = '<tb nam="' . $tb["name"] . '" />' . self::R;
                     file_put_contents($FsUnI, $e, FILE_APPEND | LOCK_EX);
                     $db->exec("ALTER TABLE " . $tb["name"] . " ADD colonia TEXT NULL AFTER codpostal;", false);
                 }
             }
             file_put_contents($FsUnI, '</databases>' . self::R . '</files>', FILE_APPEND | LOCK_EX);
         } else {
             return (bool) false;
         }
         return (bool) false;
     } else {
         return (bool) false;
     }
 }
Пример #2
0
 /**
  * Comprueba y actualiza la estructura de la tabla si es necesario
  * @param type $table_name
  * @return boolean
  */
 protected function check_table($table_name)
 {
     $done = TRUE;
     $consulta = '';
     $xml_columnas = array();
     $xml_restricciones = array();
     if ($this->get_xml_table($table_name, $xml_columnas, $xml_restricciones)) {
         if ($this->db->table_exists($table_name)) {
             if (!$this->db->check_table_aux($table_name)) {
                 $this->new_error_msg('Error al convertir la tabla a InnoDB.');
             }
             /// eliminamos restricciones
             $restricciones = $this->db->get_constraints($table_name);
             $consulta2 = $this->db->compare_constraints($table_name, $xml_restricciones, $restricciones, TRUE);
             if ($consulta2 != '') {
                 if (!$this->db->exec($consulta2)) {
                     $this->new_error_msg('Error al comprobar la tabla ' . $table_name);
                 }
             }
             /// comparamos las columnas
             $columnas = $this->db->get_columns($table_name);
             $consulta .= $this->db->compare_columns($table_name, $xml_columnas, $columnas);
             /// comparamos las restricciones
             $restricciones = $this->db->get_constraints($table_name);
             $consulta .= $this->db->compare_constraints($table_name, $xml_restricciones, $restricciones);
         } else {
             /// generamos el sql para crear la tabla
             $consulta .= $this->db->generate_table($table_name, $xml_columnas, $xml_restricciones);
             $consulta .= $this->install();
         }
         if ($consulta != '') {
             if (!$this->db->exec($consulta)) {
                 $this->new_error_msg('Error al comprobar la tabla ' . $table_name);
                 $done = FALSE;
             }
         }
     } else {
         $this->new_error_msg('Error con el xml.');
         $done = FALSE;
     }
     return $done;
 }