diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index 6fbc7df57..d0a063642 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -796,14 +796,14 @@ DROP TRIGGER IF EXISTS Zone_Insert_Trigger// CREATE TRIGGER Zone_Insert_Trigger AFTER INSERT ON Zones FOR EACH ROW BEGIN - UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=NEW.MonitorId) WHERE MonitorId=NEW.MonitorID; + UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=NEW.MonitorId) WHERE Id=NEW.MonitorID; END // DROP TRIGGER IF EXISTS Zone_Delete_Trigger// CREATE TRIGGER Zone_Delete_Trigger AFTER DELETE ON Zones FOR EACH ROW BEGIN - UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=OLD.MonitorId) WHERE MonitorId=OLD.MonitorID; + UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=OLD.MonitorId) WHERE Id=OLD.MonitorID; END // diff --git a/db/zm_update-1.31.21.sql b/db/zm_update-1.31.21.sql index 20252478a..a50fafac5 100644 --- a/db/zm_update-1.31.21.sql +++ b/db/zm_update-1.31.21.sql @@ -3,7 +3,7 @@ DROP TRIGGER IF EXISTS Zone_Insert_Trigger// CREATE TRIGGER Zone_Insert_Trigger AFTER INSERT ON Zones FOR EACH ROW BEGIN - UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=NEW.MonitorId) WHERE MonitorId=NEW.MonitorID; + UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=NEW.MonitorId) WHERE Id=NEW.MonitorID; END // @@ -11,7 +11,7 @@ DROP TRIGGER IF EXISTS Zone_Delete_Trigger// CREATE TRIGGER Zone_Delete_Trigger AFTER DELETE ON Zones FOR EACH ROW BEGIN - UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=OLD.MonitorId) WHERE MonitorId=OLD.MonitorID; + UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=OLD.MonitorId) WHERE Id=OLD.MonitorID; END // diff --git a/db/zm_update-1.31.22.sql b/db/zm_update-1.31.22.sql new file mode 100644 index 000000000..04533b7f4 --- /dev/null +++ b/db/zm_update-1.31.22.sql @@ -0,0 +1,19 @@ +delimiter // +DROP TRIGGER IF EXISTS Zone_Insert_Trigger// +CREATE TRIGGER Zone_Insert_Trigger AFTER INSERT ON Zones +FOR EACH ROW + BEGIN + UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=NEW.MonitorId) WHERE Id=NEW.MonitorID; + END +// + +DROP TRIGGER IF EXISTS Zone_Delete_Trigger// +CREATE TRIGGER Zone_Delete_Trigger AFTER DELETE ON Zones +FOR EACH ROW + BEGIN + UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=OLD.MonitorId) WHERE Id=OLD.MonitorID; + END +// + +UPDATE Monitors SET ZoneCount=(SELECT COUNT(Id) FROM Zones WHERE MonitorId=Monitors.Id)// +UPDATE Storage SET DiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE StorageId=Storage.Id); diff --git a/version b/version index 96729c873..f6cb7f351 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.31.21 +1.31.22 diff --git a/web/includes/Storage.php b/web/includes/Storage.php index 44749089a..335b8d2cd 100644 --- a/web/includes/Storage.php +++ b/web/includes/Storage.php @@ -120,6 +120,7 @@ public static function find_all( $parameters = null, $options = null ) { } $used = $this->disk_used_space(); $usage = round( ($used / $total) * 100); + Warning("Used $usage = round( ( $used / $total ) * 100 )"); return $usage; } public function disk_total_space() { @@ -130,7 +131,7 @@ public static function find_all( $parameters = null, $options = null ) { } public function disk_used_space() { # This isn't a function like this in php, so we have to add up the space used in each event. - if ( ! array_key_exists( 'DiskSpace', $this ) ) { + if ( (! array_key_exists( 'DiskSpace', $this )) or (!$this->{'DiskSpace'}) ) { $used = 0; if ( $this->{'Type'} == 's3fs' ) { $used = dbFetchOne('SELECT SUM(DiskSpace) AS DiskSpace FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL', 'DiskSpace', array($this->Id()) );