Changeset 890 for trunk/Packages/Common
- Timestamp:
- Dec 29, 2020, 11:11:12 PM (4 years ago)
- Location:
- trunk/Packages/Common
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/AppModule.php
r889 r890 90 90 $this->Stop(); 91 91 $this->Installed = false; 92 $List = array(); 92 $List = array(); 93 93 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed)); 94 94 $this->Manager->Perform($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed)); … … 187 187 function InstallModel(ModelDesc $ModelDesc) 188 188 { 189 $Query = 'CREATE TABLE IF NOT EXISTS `'.$ModelDesc->Name.'` ('."\n";190 $Query = ' `'.$ModelDesc->PrimaryKey.'` int(11) NOT NULL AUTO_INCREMENT,'."\n";189 $Query = "CREATE TABLE IF NOT EXISTS `".$ModelDesc->Name."` (\n"; 190 $Query .= ' `'.$ModelDesc->PrimaryKey.'` int(11) NOT NULL AUTO_INCREMENT,'."\n"; 191 191 foreach ($ModelDesc->Columns as $Column) 192 192 { … … 198 198 else if ($Column->Type == ModelColumnType::DateTime) $Query .= 'datetime'; 199 199 else if ($Column->Type == ModelColumnType::Reference) $Query .= 'int(11)'; 200 else if ($Column->Type == ModelColumnType::Boolean) $Query .= 'tinyint(1)'; 201 else if ($Column->Type == ModelColumnType::Date) $Query .= 'date'; 202 else if ($Column->Type == ModelColumnType::Enum) 203 { 204 $Query .= 'enum("'.implode('", "', $Column->States).'")'; 205 } 200 206 201 207 if ($Column->Nullable) $Query .= ''; … … 212 218 $Query .= ",\n"; 213 219 } 214 $Query .= ' PRIMARY KEY (`'.$ModelDesc->PrimaryKey.'`) ,';220 $Query .= ' PRIMARY KEY (`'.$ModelDesc->PrimaryKey.'`)'; 215 221 foreach ($ModelDesc->Columns as $Column) 216 222 { 217 223 if ($Column->Type == ModelColumnType::Reference) 218 $Query .= ' KEY `'.$Column->Name.'` (`'.$Column->Name.'`)'."\n";224 $Query .= ','."\n".' KEY `'.$Column->Name.'` (`'.$Column->Name.'`)'; 219 225 else if ($Column->Unique) 220 $Query .= ' UNIQUE KEY `'.$Column->Name.'` (`'.$Column->Name.'`)'."\n"; 221 } 222 223 $Query .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;"; 226 $Query .= ','."\n".' UNIQUE KEY `'.$Column->Name.'` (`'.$Column->Name.'`)'; 227 } 228 $Query .= "\n"; 229 230 if ($ModelDesc->Memory) $Engine = 'MEMORY'; 231 else $Engine = 'InnoDB'; 232 $Query .= ') ENGINE='.$Engine.' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'; 224 233 $I = 1; 225 234 foreach ($ModelDesc->Columns as $Column) … … 229 238 "ADD CONSTRAINT `".$ModelDesc->Name."_ibfk_".$I."` FOREIGN KEY (`".$Column->Name."`) REFERENCES `".$Column->RefTable."` (`Id`);"; 230 239 } 240 echo($Query); 231 241 $this->Database->query($Query); 232 242 } … … 234 244 function UninstallModel(ModelDesc $ModelDesc) 235 245 { 236 $this->Database->query('DROP TABLE `'.$ModelDesc->Name.'`');246 $this->Database->query('DROP TABLE IF EXISTS `'.$ModelDesc->Name.'`'); 237 247 } 238 248 } … … 289 299 $DepModule = $this->Modules[$Dependency]; 290 300 if (in_array(ModuleCondition::All, $Conditions) or 291 ($ Module->Running and in_array(ModuleCondition::Running, $Conditions)) or292 (!$ Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or293 ($ Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or294 (!$ Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or295 ($ Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or296 (!$ Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)))301 ($DepModule->Running and in_array(ModuleCondition::Running, $Conditions)) or 302 (!$DepModule->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or 303 ($DepModule->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or 304 (!$DepModule->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or 305 ($DepModule->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 306 (!$DepModule->Installed and in_array(ModuleCondition::NotInstalled, $Conditions))) 297 307 { 298 308 array_push($List, $DepModule); … … 308 318 if (in_array($Module->Name, $RefModule->Dependencies) and 309 319 (in_array(ModuleCondition::All, $Conditions) or 310 ($ Module->Running and in_array(ModuleCondition::Running, $Conditions)) or311 (!$ Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or312 ($ Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or313 (!$ Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or314 ($ Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or315 (!$ Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions))))320 ($RefModule->Running and in_array(ModuleCondition::Running, $Conditions)) or 321 (!$RefModule->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or 322 ($RefModule->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or 323 (!$RefModule->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions)) or 324 ($RefModule->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 325 (!$RefModule->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)))) 316 326 { 317 327 array_push($List, $RefModule); -
trunk/Packages/Common/Base.php
r889 r890 38 38 { 39 39 public string $Name; 40 public bool $Nullable;41 40 public array $Columns; 42 41 public array $Indices; 43 42 public string $PrimaryKey; 44 public bool $Unique; 45 public bool $HasDefault; 46 47 function __construct(string $Name, bool $Nullable = false, bool $Unique = false) 43 public bool $Memory; 44 45 function __construct(string $Name) 48 46 { 49 47 $this->Name = $Name; 50 48 $this->Columns = array(); 51 $this-> Nullable = $Nullable;49 $this->Indices = array(); 52 50 $this->PrimaryKey = 'Id'; 53 $this-> Unique = $Unique;51 $this->Memory = false; 54 52 } 55 53 … … 61 59 } 62 60 61 function AddFloat(string $Name): ModelColumnFloat 62 { 63 $Result = new ModelColumnFloat($Name); 64 $this->Columns[] = $Result; 65 return $Result; 66 } 67 63 68 function AddInteger(string $Name): ModelColumnInteger 64 69 { … … 75 80 } 76 81 82 function AddDate(string $Name): ModelColumnDate 83 { 84 $Result = new ModelColumnDate($Name); 85 $this->Columns[] = $Result; 86 return $Result; 87 } 88 89 function AddBoolean(string $Name): ModelColumnBoolean 90 { 91 $Result = new ModelColumnBoolean($Name); 92 $this->Columns[] = $Result; 93 return $Result; 94 } 95 77 96 function AddReference(string $Name, string $RefTable): ModelColumnReference 78 97 { … … 80 99 $this->Columns[] = $Result; 81 100 return $Result; 101 } 102 103 function AddEnum(string $Name, array $States): ModelColumnEnum 104 { 105 $Result = new ModelColumnEnum($Name, $States); 106 $this->Columns[] = $Result; 107 return $Result; 108 } 109 110 function AddChangeAction(): void 111 { 112 $Column = $this->AddEnum('ChangeAction', array('add', 'modify', 'remove')); 113 $Column->Nullable = true; 114 $Column = $this->AddDateTime('ChangeTime'); 115 $Column->Nullable = true; 116 $this->AddInteger('ChangeReplaceId'); 82 117 } 83 118 } … … 91 126 const DateTime = 4; 92 127 const Reference = 5; 128 const Boolean = 6; 129 const Date = 7; 130 const Enum = 8; 93 131 } 94 132 … … 96 134 { 97 135 public string $Name; 98 public ModelColumnType $Type; 99 public 100 101 function __construct(string $Name, int $Type) 136 public int $Type; // ModelColumnType 137 public bool $Nullable; 138 public bool $Unique; 139 public bool $HasDefault; 140 141 function __construct(string $Name, int $Type, bool $Nullable = false, bool $Unique = false) 102 142 { 103 143 $this->Name = $Name; 104 144 $this->Type = $Type; 145 $this->Nullable = $Nullable; 146 $this->Unique = $Unique; 147 $this->HasDefault = false; 105 148 } 106 149 … … 128 171 } 129 172 173 class ModelColumnFloat extends ModelColumn 174 { 175 public ?float $Default; 176 177 function __construct(string $Name) 178 { 179 parent::__construct($Name, ModelColumnType::Float); 180 $this->HasDefault = false; 181 $this->Default = null; 182 } 183 184 function GetDefault(): ?string 185 { 186 return '"'.$this->Default.'"'; 187 } 188 } 189 130 190 class ModelColumnText extends ModelColumn 131 191 { … … 169 229 { 170 230 parent::__construct($Name, ModelColumnType::DateTime); 231 $this->HasDefault = false; 232 $this->Default = null; 233 } 234 235 function GetDefault(): ?string 236 { 237 return '"'.$this->Default.'"'; 238 } 239 } 240 241 class ModelColumnDate extends ModelColumn 242 { 243 public ?DateTime $Default; 244 245 function __construct(string $Name) 246 { 247 parent::__construct($Name, ModelColumnType::Date); 171 248 $this->HasDefault = false; 172 249 $this->Default = null; … … 189 266 } 190 267 } 268 269 class ModelColumnBoolean extends ModelColumn 270 { 271 public ?bool $Default; 272 273 function __construct(string $Name) 274 { 275 parent::__construct($Name, ModelColumnType::Boolean); 276 $this->HasDefault = false; 277 $this->Default = null; 278 } 279 280 function GetDefault(): ?string 281 { 282 return $this->Default; 283 } 284 } 285 286 class ModelColumnEnum extends ModelColumn 287 { 288 public ?bool $Default; 289 public array $States; 290 291 function __construct(string $Name, array $States) 292 { 293 parent::__construct($Name, ModelColumnType::Enum); 294 $this->HasDefault = false; 295 $this->Default = null; 296 $this->States = $States; 297 } 298 299 function GetDefault(): ?string 300 { 301 return $this->Default; 302 } 303 } -
trunk/Packages/Common/Database.php
r888 r890 105 105 'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n"); 106 106 $Result = new DatabaseResult(); 107 $Result->PDOStatement = $this->PDO->query($Query); 108 if ($Result->PDOStatement) 109 { 110 $Result->num_rows = $Result->PDOStatement->rowCount(); 107 $Statement = $this->PDO->query($Query); 108 if ($Statement) 109 { 110 $Result->PDOStatement = $Statement; 111 $Result->num_rows = $Statement->rowCount(); 111 112 $this->insert_id = $this->PDO->lastInsertId(); 112 113 } else -
trunk/Packages/Common/Update.php
r888 r890 18 18 } 19 19 20 function GetDbVersion(): string20 function GetDbVersion(): ?int 21 21 { 22 22 $DbResult = $this->Database->select($this->VersionTable, '*', 'Id=1');
Note:
See TracChangeset
for help on using the changeset viewer.