Changeset 401


Ignore:
Timestamp:
Mar 30, 2012, 2:02:51 PM (13 years ago)
Author:
chronos
Message:
  • Upraveno: Instalace a odinstalace je nyní spravována samostatným skriptem install.php.
  • Upraveno: Částečné řešení odstranění cizích klíčů v průběhu odinstalace před odstraněním samotných tabulek.
Location:
branches/Modular
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/Modular/Common/Database.php

    r358 r401  
    3737  var $ShowSQLError = false;
    3838  var $ShowSQLQuery = false;
     39  var $Database = '';
    3940 
    4041  function __construct($Host, $User, $Password, $Database)
    4142  {   
     43    $this->Database = $Database;
    4244    if($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database;
    4345      else if($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host;
     
    4951  function select_db($Database)
    5052  {
     53    $this->Database = $Database;
    5154    $this->query('USE '.$Database);
    5255  }
  • branches/Modular/Common/Global.php

    r384 r401  
    7373  $System->RootFolder = $Config['Web']['RootFolder'];
    7474  $System->Config = &$Config;
    75   $System->Install();
    76   $System->Init(); 
    7775}
    7876
  • branches/Modular/Common/Model.php

    r398 r401  
    236236            $this->Module->Models[$Property['TargetModel']]->Install();
    237237        }
    238         $this->Database->query('ALTER TABLE `'.$this->Name.'` ADD FOREIGN KEY (`'.$Property['Name'].'`) REFERENCES `'.$Property['TargetModel'].'` (`Id`);');
     238        $this->Database->query('ALTER TABLE `'.$this->Name.'` ADD CONSTRAINT `'.
     239          $this->Name.'_ibfk_'.$Property['Name'].'` FOREIGN KEY (`'.$Property['Name'].'`) REFERENCES `'.$Property['TargetModel'].'` (`Id`);');
    239240      }
    240     }
    241   }
     241    }  }
    242242   
    243243  function UnInstall()
     
    247247      if($Property['Type'] == PropertyManyToMany)
    248248        ; // Delete many-to-many table
     249      else
     250      {if($Property['Type'] == PropertyOneToMany)
     251        $this->Database->query('ALTER TABLE `'.$this->Name.'` DROP FOREIGN KEY `'.
     252          $this->Name.'_ibfk_'.$Property['Name'].'`');
     253      echo('ss');
     254      }
    249255    }
    250     $this->Database->query('DROP TABLE IF EXISTS `'.$this->Name.'`');
     256    //$this->Database->query('DROP TABLE IF EXISTS `'.$this->Name.'`');
    251257    $this->Installed = false;
    252258  }
  • branches/Modular/Common/Module.php

    r398 r401  
    120120  {
    121121    //DebugLog('Installing modular system core...');
     122    $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemVersion` (
     123  `Id` int(11) NOT NULL AUTO_INCREMENT,
     124  `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL,
     125  `Description` datetime NOT NULL,
     126  PRIMARY KEY (`Id`)
     127) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    122128    $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModule` (
    123129  `Id` int(11) NOT NULL AUTO_INCREMENT,
     
    140146  UNIQUE (`Module` , `DependencyModule`)
    141147) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    142     $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
    143     $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD FOREIGN KEY ( `DependencyModule` ) REFERENCES `SystemModule` (`Id`)');
     148    $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
     149    $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_2` FOREIGN KEY ( `DependencyModule` ) REFERENCES `SystemModule` (`Id`)');
    144150   
    145151    $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModel` (
     
    150156  PRIMARY KEY (`Id`)
    151157) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    152     $this->Database->query('ALTER TABLE `SystemModel` ADD FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
     158    $this->Database->query('ALTER TABLE `SystemModel` ADD CONSTRAINT `SystemModel_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
    153159   
    154160    $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModelProperty` (
     
    160166  PRIMARY KEY (`Id`)
    161167) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    162     $this->Database->query('ALTER TABLE `SystemModelProperty` ADD FOREIGN KEY ( `Model` ) REFERENCES `SystemModel` (`Id`)');
     168    $this->Database->query('ALTER TABLE `SystemModelProperty` ADD CONSTRAINT `SystemModelProperty_ibfk_1` FOREIGN KEY ( `Model` ) REFERENCES `SystemModel` (`Id`)');
    163169   
    164170    $this->ReloadList();
     
    178184   
    179185    // Delete tables with reverse order
     186    $this->Database->query('ALTER TABLE `SystemModelProperty` DROP FOREIGN KEY `SystemModelProperty_ibfk_1`');
    180187    $this->Database->query('DROP TABLE IF EXISTS `SystemModelProperty`');
     188    $this->Database->query('ALTER TABLE `SystemModel` DROP FOREIGN KEY `SystemModel_ibfk_1`');
    181189    $this->Database->query('DROP TABLE IF EXISTS `SystemModel`');
     190    $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_1`');
     191    $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_2`');
    182192    $this->Database->query('DROP TABLE IF EXISTS `SystemModuleDependency`');
    183193    $this->Database->query('DROP TABLE IF EXISTS `SystemModule`');
     194    $this->Database->query('DROP TABLE IF EXISTS `SystemVersion`');
     195  }
     196 
     197  function IsInstalled()
     198  {
     199    $DbResult = $this->Database->query('SELECT table_name FROM information_schema.tables
     200WHERE table_schema = "'.$this->Database->Database.'" AND table_name = "SystemVersion";');   
     201    if($DbResult->num_rows > 0) return(true);
     202      else return(false);
    184203  }
    185204 
  • branches/Modular/Install.php

    r377 r401  
    22
    33include_once('Common/Global.php');
     4GlobalInit();
    45
     6function ShowDefault()
     7{
     8  global $System;
     9 
     10  if($System->IsInstalled())
     11  {
     12    echo('System je již nainstalován.<br/>');
     13    echo('<a href="?a=uninstall">Odinstalovat systém</a>');
     14  } else
     15  {
     16    echo('System ještě není instalován.<br/>');
     17    echo('<a href="?a=install">Instalovat systém</a>');
     18  }
     19}
     20
     21if(array_key_exists('a', $_GET))
     22{
     23  if($_GET['a'] == 'install')
     24  {     
     25    $System->Install();
     26    $System->Init(); 
     27    ShowDefault();
     28  }
     29  else if($_GET['a'] == 'uninstall')
     30  {
     31    $System->Init(); 
     32    $System->Uninstall();
     33    ShowDefault();
     34  }
     35  else ShowDefault();
     36} else ShowDefault();
    537
    638?>
  • branches/Modular/index.php

    r384 r401  
    33include_once('Common/Global.php');
    44GlobalInit();
     5if(!$System->IsInstalled()) die('System not installed.');
     6$System->Init(); 
    57$System->PathItems = ProcessURL();
    68//print_r($_GET);
Note: See TracChangeset for help on using the changeset viewer.