Changeset 891 for trunk/Modules/Notify/Notify.php
- Timestamp:
- Dec 30, 2020, 11:52:07 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Notify/Notify.php
r887 r891 128 128 } 129 129 130 static function GetModels(): array 131 { 132 return array( 133 'NotifyCategory', 134 'NotifyUser', 135 ); 136 } 137 130 138 function DoInstall(): void 131 139 { 132 $this->Database->query('CREATE TABLE IF NOT EXISTS `NotifyCategory` ( 133 `Id` int(11) NOT NULL AUTO_INCREMENT, 134 `Name` varchar(255) NOT NULL, 135 `SysName` varchar(255) NOT NULL, 136 PRIMARY KEY (`Id`) 137 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;'); 140 foreach (self::GetModels() as $Model) 141 { 142 $this->InstallModel($Model::GetDesc()); 143 } 138 144 139 145 $this->Database->query("INSERT INTO `NotifyCategory` (`Id`, `Name`, `SysName`) VALUES … … 144 150 (5, 'Minimální odezva', 'NetworkLatency'), 145 151 (6, 'Minimální propustnost', 'NetworkBandwidth');"); 146 147 $this->Database->query('148 CREATE TABLE IF NOT EXISTS `NotifyUser` (149 `Id` int(11) NOT NULL AUTO_INCREMENT,150 `User` int(11) NOT NULL,151 `Contact` int(11) NOT NULL,152 `Period` int(11) NOT NULL,153 PRIMARY KEY (`Id`),154 KEY `User` (`User`),155 KEY `Contact` (`Contact`)156 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;');157 $this->Database->query('ALTER TABLE `NotifyUser`158 ADD CONSTRAINT `NotifyUser_ibfk_1` FOREIGN KEY (`User`) REFERENCES `User` (`Id`),159 ADD CONSTRAINT `NotifyUser_ibfk_2` FOREIGN KEY (`Contact`) REFERENCES `Contact` (`Id`);');160 152 } 161 153 162 154 function DoUninstall(): void 163 155 { 164 $this->Database->query('DROP TABLE `NotifyUser`'); 165 $this->Database->query('DROP TABLE `NotifyCategory`'); 156 foreach (array_reverse(self::GetModels()) as $Model) 157 { 158 $this->UninstallModel($Model::GetDesc()); 159 } 166 160 } 167 161 … … 207 201 } 208 202 } 203 204 class NotifyCategory extends Model 205 { 206 static function GetDesc(): ModelDesc 207 { 208 $Desc = new ModelDesc('NotifyCategory'); 209 $Desc->AddString('Name'); 210 $Desc->AddString('SysName'); 211 return $Desc; 212 } 213 } 214 215 class NotifyUser extends Model 216 { 217 static function GetDesc(): ModelDesc 218 { 219 $Desc = new ModelDesc('NotifyUser'); 220 $Desc->AddReference('User', 'User'); 221 $Desc->AddReference('Contact', 'Contact'); 222 $Desc->AddInteger('Period'); 223 return $Desc; 224 } 225 }
Note:
See TracChangeset
for help on using the changeset viewer.