Changeset 890
- Timestamp:
- Dec 29, 2020, 11:11:12 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/UpdateTrace.php
r887 r890 2133 2133 { 2134 2134 $Manager->Execute('ALTER TABLE `FinanceOperation` CHANGE `Value` `Value` FLOAT NOT NULL DEFAULT "0";'); 2135 $Manager->Execute('ALTER TABLE `NetworkInterface` CHANGE `OnlineNotify` `OnlineNotify` INT(11) NOT NULL DEFAULT "0";'); 2135 2136 } 2136 2137 -
trunk/Modules/API/API.php
r889 r890 25 25 $this->License = 'GNU/GPL'; 26 26 $this->Description = 'Remote API for support of other clients'; 27 $this->Dependencies = array( );27 $this->Dependencies = array('User'); 28 28 } 29 29 -
trunk/Modules/Customer/Customer.php
r887 r890 11 11 $this->License = 'GNU/GPL'; 12 12 $this->Description = 'Customer management'; 13 $this->Dependencies = array('User' );13 $this->Dependencies = array('User', 'Finance'); 14 14 } 15 15 … … 191 191 } 192 192 193 function DoInstall(): void 194 { 195 $this->InstallModel(Member::GetDesc()); 196 $this->InstallModel(MemberPayment::GetDesc()); 197 $this->InstallModel(SupportActivity::GetDesc()); 198 $this->InstallModel(ServiceCategory::GetDesc()); 199 $this->InstallModel(Service::GetDesc()); 200 $this->InstallModel(ServiceCustomerRel::GetDesc()); 201 } 202 203 function Uninstall(): void 204 { 205 $this->UninstallModel(ServiceCustomerRel::GetDesc()); 206 $this->UninstallModel(Service::GetDesc()); 207 $this->UninstallModel(ServiceCategory::GetDesc()); 208 $this->UninstallModel(SupportActivity::GetDesc()); 209 $this->UninstallModel(MemberPayment::GetDesc()); 210 $this->UninstallModel(Member::GetDesc()); 211 } 212 193 213 function ShowDashboardItem(): string 194 214 { … … 203 223 return $Output; 204 224 } 205 206 } 225 } 226 227 class Member extends Model 228 { 229 static function GetDesc(): ModelDesc 230 { 231 $Desc = new ModelDesc('Member'); 232 $Desc->AddString('Name'); 233 $Desc->AddReference('Subject', 'Subject'); 234 $Desc->AddReference('ResponsibleUser', 'User'); 235 $Desc->AddInteger('FamilyMemberCount'); 236 $Desc->AddDate('MembershipDate'); 237 $Desc->AddInteger('MemberState'); 238 $Desc->AddInteger('GPS'); 239 $Desc->AddReference('BillingPeriod', 'FinanceBillingPerios'); 240 $Desc->AddDate('BillingPeriodLastDate'); 241 $Desc->AddBoolean('Blocked'); 242 $Desc->AddInteger('PayDay'); 243 $Desc->AddChangeAction(); 244 return $Desc; 245 } 246 } 247 248 class MemberPayment extends Model 249 { 250 static function GetDesc(): ModelDesc 251 { 252 $Desc = new ModelDesc('MemberPayment'); 253 $Desc->AddReference('Member', 'Member'); 254 $Desc->AddFloat('MonthlyTotal'); 255 $Desc->AddFloat('MonthlyInternet'); 256 $Desc->AddFloat('MonthlyConsumption'); 257 $Desc->AddFloat('MonthlyPlus'); 258 $Desc->AddFloat('Cash'); 259 return $Desc; 260 } 261 } 262 263 class Service extends Model 264 { 265 static function GetDesc(): ModelDesc 266 { 267 $Desc = new ModelDesc('Service'); 268 $Desc->AddString('Name'); 269 $Desc->AddReference('Category', 'ServiceCategory'); 270 $Desc->AddInteger('Price'); 271 $Desc->AddInteger('VAT'); 272 $Desc->AddChangeAction(); 273 $Desc->AddBoolean('Public'); 274 $Desc->AddInteger('InternetSpeedMax'); 275 $Desc->AddInteger('InternetSpeedMin'); 276 $Desc->AddInteger('InternetUploadAsymmetry'); 277 $Desc->AddInteger('Memory'); 278 $Desc->AddInteger('MemorySwap'); 279 $Desc->AddInteger('Storage'); 280 $Desc->AddInteger('CPUCount'); 281 return $Desc; 282 } 283 } 284 285 class ServiceCategory extends Model 286 { 287 static function GetDesc(): ModelDesc 288 { 289 $Desc = new ModelDesc('ServiceCategory'); 290 $Desc->AddString('Name'); 291 return $Desc; 292 } 293 } 294 295 class SupportActivity extends Model 296 { 297 static function GetDesc(): ModelDesc 298 { 299 $Desc = new ModelDesc('SupportActivity'); 300 $Desc->AddDateTime('Time'); 301 $Desc->AddString('Description'); 302 $Desc->AddReference('Customer', 'Member'); 303 $Desc->AddReference('User', 'User'); 304 return $Desc; 305 } 306 } 307 308 class ServiceCustomerRel extends Model 309 { 310 static function GetDesc(): ModelDesc 311 { 312 $Desc = new ModelDesc('ServiceCustomerRel'); 313 $Desc->AddReference('Service', 'Service'); 314 $Desc->AddReference('Customer', 'Member'); 315 $Desc->AddChangeAction(); 316 $Desc->AddInteger('SpeedLimit'); 317 return $Desc; 318 } 319 } -
trunk/Modules/File/File.php
r887 r890 11 11 parent::__construct($System); 12 12 $this->FilesDir = ''; 13 } 14 15 static function GetDesc(): ModelDesc 16 { 17 $Desc = new ModelDesc('File'); 18 $Desc->AddString('Name'); 19 $Desc->AddInteger('Size'); 20 $Column = $Desc->AddReference('Directory', 'FileDirectory'); 21 $Column->Nullable = true; 22 $Desc->AddDateTime('Time'); 23 return $Desc; 13 24 } 14 25 … … 104 115 } 105 116 117 class FileDirectory extends Model 118 { 119 static function GetDesc(): ModelDesc 120 { 121 $Desc = new ModelDesc('FileDirectory'); 122 $Desc->AddString('Name'); 123 $Column = $Desc->AddReference('Parent', 'FileDirectory'); 124 $Column->Nullable = true; 125 return $Desc; 126 } 127 } 128 106 129 class PageFileCheck extends Page 107 130 { … … 173 196 function DoInstall(): void 174 197 { 198 $this->InstallModel(FileDirectory::GetDesc()); 199 $this->InstallModel(File::GetDesc()); 175 200 } 176 201 177 202 function DoUninstall(): void 178 203 { 204 $this->UninstallModel(File::GetDesc()); 205 $this->UninstallModel(FileDirectory::GetDesc()); 179 206 } 180 207 -
trunk/Modules/Finance/Finance.php
r888 r890 277 277 'Treasury' => array('Type' => 'TFinanceTreasury', 'Caption' => 'Pokladna', 'Default' => '', 'Null' => true), 278 278 'Generate' => array('Type' => 'Boolean', 'Caption' => 'Generovat', 'Default' => ''), 279 'Balance' => array('Type' => 'Integer', 'Caption' => 'Zůstatek', 'Default' => '', 280 'ReadOnly' => true, 'SQL' => '(SELECT SUM(`FinanceOperation2`.`Value`) FROM `FinanceOperation` AS `FinanceOperation2` WHERE `FinanceOperation2`.`Time`<`Time`)'), 279 281 'InvoiceRel' => array('Type' => 'TFinanceInvoiceOperationRelListOperation', 'Caption' => 'Zaplacené faktury', 'Default' => ''), 280 282 'InvoiceRelCount' => array('Type' => 'Integer', 'Caption' => 'Faktur', … … 289 291 ), 290 292 )); 291 293 292 294 $this->System->FormManager->RegisterClass('FinanceTreasuryIn', $this->System->FormManager->Classes['FinanceOperation']); 293 295 $this->System->FormManager->Classes['FinanceTreasuryIn']['Title'] = 'Pokladní příjmy'; … … 543 545 ), 544 546 )); 547 $this->System->FormManager->RegisterClass('FinanceBankAccountReport', array( 548 'Title' => 'Roční výkaz operací', 549 'Table' => 'FinanceBankAccountReport', 550 'SQL' => 'SELECT Id, DateEnd, DateStart FROM FinanceYear', 551 'DefaultSortColumn' => 'Id', 552 'Items' => array( 553 'Id' => array('Type' => 'TFinanceYear', 'Caption' => 'Rok', 'Default' => '', 554 'ReadOnly' => true), 555 //'Account' => array('Type' => 'TFinanceBankAccount', 'Caption' => 'Bankovní účet', 'Default' => '', 556 // 'ReadOnly' => true), 557 'StartBalance' => array('Type' => 'Integer', 'Caption' => 'Starý zůstatek', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true, 558 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '. 559 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '. 560 'WHERE (`FinanceOperation`.`Time` <= `DateStart`) AND (`FinanceOperation`.`BankAccount` = 2))'), 561 'EndBalance' => array('Type' => 'Integer', 'Caption' => 'Nový zůstatek', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true, 562 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '. 563 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '. 564 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) AND (`FinanceOperation`.`BankAccount` = 2))'), 565 'Change' => array('Type' => 'Integer', 'Caption' => 'Změna', 'Default' => '0', 'Suffix' => 'Kč', 'ReadOnly' => true, 566 'SQL' => '(SELECT ROUND(SUM(`FinanceOperation`.`Value`)) FROM `FinanceOperation` '. 567 'LEFT JOIN `FinanceOperationGroup` ON `FinanceOperationGroup`.`Id`=`FinanceOperation`.`Group` '. 568 'WHERE (`FinanceOperation`.`Time` <= `DateEnd`) '. 569 'AND (`FinanceOperation`.`Time` >= `DateStart`) AND (`FinanceOperation`.`BankAccount` = 2))'), 570 ), 571 //'AfterInsert' => array($this, 'AfterInsertFinanceYear'), 572 )); 545 573 $this->System->FormManager->RegisterFormType('TFinanceBankAccount', array( 546 574 'Type' => 'Reference', -
trunk/Modules/User/User.php
r887 r890 25 25 function DoInstall(): void 26 26 { 27 $this->Database->query("CREATE TABLE IF NOT EXISTS `User` ( 28 `Id` int(11) NOT NULL AUTO_INCREMENT, 29 `Login` varchar(64) NOT NULL, 30 `Name` varchar(128) NOT NULL, 31 `Password` varchar(255) NOT NULL, 32 `Salt` varchar(255) NOT NULL, 33 `Email` varchar(128) NOT NULL DEFAULT '', 34 `LastIpAddress` varchar(16) NOT NULL DEFAULT '', 35 `LastLoginTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 36 `RegistrationTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 37 `Locked` tinyint(1) NOT NULL DEFAULT '0', 38 `InitPassword` varchar(255) NOT NULL, 39 PRIMARY KEY (`Id`), 40 UNIQUE KEY `Name` (`Login`), 41 UNIQUE KEY `Nick` (`Name`) 42 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 43 $this->Database->query("CREATE TABLE IF NOT EXISTS `UserOnline` ( 44 `Id` int(11) NOT NULL AUTO_INCREMENT, 45 `User` int(11) DEFAULT NULL COMMENT 'User.Id', 46 `ActivityTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 47 `LoginTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 48 `SessionId` varchar(255) NOT NULL DEFAULT '', 49 `IpAddress` varchar(16) NOT NULL DEFAULT '', 50 `HostName` varchar(255) NOT NULL DEFAULT '', 51 `ScriptName` varchar(255) NOT NULL, 52 `StayLogged` INT NOT NULL, 53 `StayLoggedHash` VARCHAR(40) NOT NULL, 54 PRIMARY KEY (`Id`), 55 KEY `User` (`User`) 56 ) ENGINE=MEMORY DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 57 $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionGroup` ( 58 `Id` int(11) NOT NULL AUTO_INCREMENT, 59 `Description` varchar(255) NOT NULL DEFAULT '', 60 PRIMARY KEY (`Id`) 61 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 62 63 $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionGroupAssignment` ( 64 `Id` int(11) NOT NULL AUTO_INCREMENT, 65 `Group` int(11) NOT NULL DEFAULT '0', 66 `AssignedGroup` int(11) DEFAULT NULL, 67 `AssignedOperation` int(11) DEFAULT NULL, 68 PRIMARY KEY (`Id`), 69 KEY `Group` (`Group`), 70 KEY `AssignedGroup` (`AssignedGroup`), 71 KEY `AssignedOperation` (`AssignedOperation`) 72 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 73 74 $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionOperation` ( 75 `Id` int(11) NOT NULL AUTO_INCREMENT, 76 `Module` int(11) NOT NULL, 77 `Operation` varchar(128) NOT NULL DEFAULT '', 78 `Item` varchar(64) NOT NULL DEFAULT '', 79 `ItemId` int(11) NOT NULL DEFAULT '0', 80 PRIMARY KEY (`Id`), 81 KEY `Module` (`Module`), 82 KEY `Operation` (`Operation`), 83 KEY `Item` (`Item`), 84 KEY `ItemId` (`ItemId`) 85 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 86 87 $this->Database->query("CREATE TABLE IF NOT EXISTS `PermissionUserAssignment` ( 88 `Id` int(11) NOT NULL AUTO_INCREMENT, 89 `User` int(11) DEFAULT NULL, 90 `AssignedGroup` int(11) DEFAULT NULL, 91 `AssignedOperation` int(11) DEFAULT NULL, 92 PRIMARY KEY (`Id`), 93 KEY `User` (`User`), 94 KEY `AssignedGroup` (`AssignedGroup`), 95 KEY `AssignedOperation` (`AssignedOperation`) 96 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); 97 98 $this->Database->query("ALTER TABLE `PermissionGroupAssignment` 99 ADD CONSTRAINT `PermissionGroupAssignment_ibfk_1` FOREIGN KEY (`Group`) REFERENCES `PermissionGroup` (`Id`), 100 ADD CONSTRAINT `PermissionGroupAssignment_ibfk_2` FOREIGN KEY (`AssignedGroup`) REFERENCES `PermissionGroup` (`Id`), 101 ADD CONSTRAINT `PermissionGroupAssignment_ibfk_3` FOREIGN KEY (`AssignedOperation`) REFERENCES `PermissionOperation` (`Id`);"); 102 103 $this->Database->query("ALTER TABLE `PermissionOperation` 104 ADD CONSTRAINT `PermissionOperation_ibfk_1` FOREIGN KEY (`Module`) REFERENCES `Module` (`Id`);"); 105 106 $this->Database->query("ALTER TABLE `PermissionUserAssignment` 107 ADD CONSTRAINT `PermissionUserAssignment_ibfk_2` FOREIGN KEY (`AssignedGroup`) REFERENCES `PermissionGroup` (`Id`), 108 ADD CONSTRAINT `PermissionUserAssignment_ibfk_3` FOREIGN KEY (`AssignedOperation`) REFERENCES `PermissionOperation` (`Id`), 109 ADD CONSTRAINT `PermissionUserAssignment_ibfk_4` FOREIGN KEY (`User`) REFERENCES `User` (`Id`);"); 27 $this->InstallModel(User::GetDesc()); 28 $this->InstallModel(UserOnline::GetDesc()); 29 $this->InstallModel(PermissionGroup::GetDesc()); 30 $this->InstallModel(PermissionOperation::GetDesc()); 31 $this->InstallModel(PermissionGroupAssignment::GetDesc()); 32 $this->InstallModel(PermissionUserAssignment::GetDesc()); 110 33 } 111 34 112 35 function DoUninstall(): void 113 36 { 114 $this->Database->query('DROP TABLE `PermissionUserAssignment`'); 115 $this->Database->query('DROP TABLE `PermissionGroupAssignment`'); 116 $this->Database->query('DROP TABLE `PermissionGroup`'); 117 $this->Database->query('DROP TABLE `PermissionOperation`'); 118 $this->Database->query('DROP TABLE `UserOnline`'); 119 $this->Database->query('DROP TABLE `User`'); 120 } 121 122 function DoUpgrade(): void 123 { 124 /* 125 126 if ($this->InstalledVersion == '1.0') { 127 $this->System->Database->Query('SELECT * FROM User WHERE Id=1'); 128 $this->InstalledVersion = '1.1'; 129 } 130 */ 37 $this->UninstallModel(PermissionUserAssignment::GetDesc()); 38 $this->UninstallModel(PermissionGroupAssignment::GetDesc()); 39 $this->UninstallModel(PermissionOperation::GetDesc()); 40 $this->UninstallModel(PermissionGroup::GetDesc()); 41 $this->UninstallModel(UserOnline::GetDesc()); 42 $this->UninstallModel(User::GetDesc()); 131 43 } 132 44 -
trunk/Modules/User/UserModel.php
r887 r890 65 65 } 66 66 67 static function GetDesc(): ModelDesc 68 { 69 $Desc = new ModelDesc('User'); 70 $Column = $Desc->AddString('Login'); 71 $Column->Unique = true; 72 $Column = $Desc->AddString('Name'); 73 $Column->Unique = true; 74 $Desc->AddString('Password'); 75 $Desc->AddString('Salt'); 76 $Desc->AddString('Email'); 77 $Desc->AddString('LastIpAddress'); 78 $Desc->AddString('LastLoginTime'); 79 $Desc->AddDateTime('RegistrationTime'); 80 $Desc->AddBoolean('Locked'); 81 $Desc->AddString('InitPassword'); 82 return $Desc; 83 } 84 67 85 function Check(): void 68 86 { … … 435 453 } 436 454 } 455 456 class UserOnline extends Model 457 { 458 static function GetDesc(): ModelDesc 459 { 460 $Desc = new ModelDesc('UserOnline'); 461 $Desc->Memory = true; 462 $Column = $Desc->AddReference('User', 'User'); 463 $Column->Nullable = true; 464 $Desc->AddDateTime('ActivityTime'); 465 $Desc->AddDateTime('LoginTime'); 466 $Desc->AddString('SessionId'); 467 $Desc->AddString('IpAddress'); 468 $Desc->AddString('HostName'); 469 $Desc->AddString('ScriptName'); 470 $Desc->AddBoolean('StayLogged'); 471 $Desc->AddString('StayLoggedHash'); 472 return $Desc; 473 } 474 } 475 476 class PermissionGroup extends Model 477 { 478 static function GetDesc(): ModelDesc 479 { 480 $Desc = new ModelDesc('PermissionGroup'); 481 $Desc->AddString('Description'); 482 return $Desc; 483 } 484 } 485 486 class PermissionGroupAssignment extends Model 487 { 488 static function GetDesc(): ModelDesc 489 { 490 $Desc = new ModelDesc('PermissionGroupAssignment'); 491 $Desc->AddReference('Group', 'PermissionGroup'); 492 $Column = $Desc->AddReference('AssignedGroup', 'PermissionGroup'); 493 $Column->Nullable = true; 494 $Column = $Desc->AddReference('AssignedOperation', 'PermissionOperation'); 495 $Column->Nullable = true; 496 return $Desc; 497 } 498 } 499 500 class PermissionOperation extends Model 501 { 502 static function GetDesc(): ModelDesc 503 { 504 $Desc = new ModelDesc('PermissionOperation'); 505 $Desc->AddReference('Module', 'Module'); 506 $Desc->AddString('Operation'); 507 $Desc->AddString('Item'); 508 $Desc->AddInteger('ItemId'); 509 $Desc->Indices = array('Operation', 'Item', 'ItemId'); 510 return $Desc; 511 } 512 } 513 514 class PermissionUserAssignment extends Model 515 { 516 static function GetDesc(): ModelDesc 517 { 518 $Desc = new ModelDesc('PermissionUserAssignment'); 519 $Desc->AddReference('User', 'User'); 520 $Column = $Desc->AddReference('AssignedGroup', 'PermissionGroup'); 521 $Column->Nullable = true; 522 $Column = $Desc->AddReference('AssignedOperation', 'PermissionOperation'); 523 $Column->Nullable = true; 524 return $Desc; 525 } 526 } -
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.