From a03ceec154ef605a83087e815cf71e6bfc9e1a2a Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Jan 2018 13:29:45 -0500 Subject: [PATCH 1/9] Fix Day=>Wek --- db/zm_update-1.31.24.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/zm_update-1.31.24.sql b/db/zm_update-1.31.24.sql index 9f7bad11c..008618baa 100644 --- a/db/zm_update-1.31.24.sql +++ b/db/zm_update-1.31.24.sql @@ -35,7 +35,7 @@ PREPARE stmt FROM @sqlstmt; EXECUTE stmt; set @exist := (select count(*) from information_schema.statistics where table_name = 'Events_Week' and index_name = 'Events_Week_MonitorId_idx' and table_schema = database()); -set @sqlstmt := if( @exist > 0, "SELECT 'Events_Week_MonitorId_idx INDEX already exists.'", "CREATE INDEX `Events_Week_MonitorId_idx` ON `Events_Day` (`MonitorId`)"); +set @sqlstmt := if( @exist > 0, "SELECT 'Events_Week_MonitorId_idx INDEX already exists.'", "CREATE INDEX `Events_Week_MonitorId_idx` ON `Events_Week` (`MonitorId`)"); PREPARE stmt FROM @sqlstmt; EXECUTE stmt; From dfce773341965c946be26f4d83d3d8ccf6f7887d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Jan 2018 13:32:28 -0500 Subject: [PATCH 2/9] We should return the value of DiskSpace --- scripts/ZoneMinder/lib/ZoneMinder/Event.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm index c2d8f9850..957488d9e 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm @@ -449,6 +449,7 @@ sub DiskSpace { Warning("Event does not exist at $_[0]{Path}"); } } # end if ! defined DiskSpace + return $_[0]{DiskSpace}; } sub MoveTo { From e372a490fa0ad42526178763e42e99c9241b8fee Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Jan 2018 13:32:58 -0500 Subject: [PATCH 3/9] bump version --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 5a6a9e563..fca4bdfac 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.31.25 +1.31.26 From 268268606356bbcea526f45a513fc0b469ee52b3 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Jan 2018 16:32:26 -0500 Subject: [PATCH 4/9] Must disconnect and reconnect before calling update script --- scripts/zmupdate.pl.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/zmupdate.pl.in b/scripts/zmupdate.pl.in index 5e7b72411..9e8358e03 100644 --- a/scripts/zmupdate.pl.in +++ b/scripts/zmupdate.pl.in @@ -932,6 +932,8 @@ sub patchDB { my $dbh = shift; my $version = shift; + zmDbDisconnect(); + my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ ); my $command = 'mysql'; if ( defined($portOrSocket) ) { @@ -966,6 +968,8 @@ sub patchDB { die( "Command '$command' exited with status: $status\n" ); } print( "\nDatabase successfully upgraded to version $version.\n" ); + + $dbh = zmDbConnect(); my $sql = "update Config set Value = ? where Name = 'ZM_DYN_DB_VERSION'"; my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); my $res = $sth->execute( $version ) or die( "Can't execute: ".$sth->errstr() ); From 1291835c4524c28013a1a493fa49aaa08e15bd93 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Jan 2018 16:32:48 -0500 Subject: [PATCH 5/9] do some output to tell use what we are doing during update process --- db/zm_update-1.31.0.sql | 6 +++++- db/zm_update-1.31.1.sql | 1 + db/zm_update-1.31.2.sql | 1 + db/zm_update-1.31.3.sql | 10 ++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/db/zm_update-1.31.0.sql b/db/zm_update-1.31.0.sql index 7daadd974..1e20953d6 100644 --- a/db/zm_update-1.31.0.sql +++ b/db/zm_update-1.31.0.sql @@ -1,7 +1,7 @@ -- -- This updates a 1.29.0 database to 1.30.0 -- - +SELECT 'Checking for SaveJPEGs in Monitors'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS @@ -16,6 +16,7 @@ SET @s = (SELECT IF( PREPARE stmt FROM @s; EXECUTE stmt; +SELECT 'Checking for VideoWriter in Monitors'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS @@ -30,6 +31,7 @@ SET @s = (SELECT IF( PREPARE stmt FROM @s; EXECUTE stmt; +SELECT 'Checking for EncoderParameters in Monitors'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS @@ -44,6 +46,7 @@ SET @s = (SELECT IF( PREPARE stmt FROM @s; EXECUTE stmt; +SELECT 'Checking for DefaultVideo in Events'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS @@ -58,6 +61,7 @@ SET @s = (SELECT IF( PREPARE stmt FROM @s; EXECUTE stmt; +SELECT 'Checking for RecordAudio in Monitors'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS diff --git a/db/zm_update-1.31.1.sql b/db/zm_update-1.31.1.sql index 18d825091..399a100bb 100644 --- a/db/zm_update-1.31.1.sql +++ b/db/zm_update-1.31.1.sql @@ -3,6 +3,7 @@ -- -- Add StateId Column to Events. -- +SELECT 'Checkfor StateId IN Events'; SET @s = (SELECT IF( (SELECT COUNT(*) diff --git a/db/zm_update-1.31.2.sql b/db/zm_update-1.31.2.sql index d918db17b..3e40885a4 100644 --- a/db/zm_update-1.31.2.sql +++ b/db/zm_update-1.31.2.sql @@ -2,6 +2,7 @@ -- Update Filters table to have a Concurrent Column -- +SELECT 'Checking for Concurrent in Filters'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS diff --git a/db/zm_update-1.31.3.sql b/db/zm_update-1.31.3.sql index 0f1e6850c..733efcedd 100644 --- a/db/zm_update-1.31.3.sql +++ b/db/zm_update-1.31.3.sql @@ -2,6 +2,7 @@ -- This adds StorageAreas -- +SELECT 'Checking For Storage Table'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES @@ -24,6 +25,7 @@ EXECUTE stmt; -- Add StorageId column to Monitors -- +SELECT 'Checking For StorageId in Monitors'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS @@ -42,6 +44,7 @@ EXECUTE stmt; -- Add StorageId column to Eventss -- +SELECT 'Checking For StorageId in Events'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS @@ -56,6 +59,7 @@ SET @s = (SELECT IF( PREPARE stmt FROM @s; EXECUTE stmt; +SELECT 'Updating Monitors SETTING StorageId to default'; UPDATE Monitors SET StorageId = 0 WHERE StorageId IS NULL; ALTER TABLE Monitors MODIFY `StorageId` smallint(5) unsigned NOT NULL default 0; UPDATE Events SET StorageId = 0 WHERE StorageId IS NULL; @@ -78,6 +82,7 @@ EXECUTE stmt; -- -- Update Monitors table to have an Index on ServerId -- +SELECT 'Create Index For ServerId on Monitors'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS @@ -96,6 +101,7 @@ EXECUTE stmt; -- -- Update Server table to have an Index on Name -- +SELECT 'Create Index FOR Name on Servers'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS @@ -111,15 +117,19 @@ PREPARE stmt FROM @s; EXECUTE stmt; +SELECT 'ALTER TABLE Logs MODIFY Message TEXT NOT NULL'; -- ALTER TABLE Logs ALTER Message DROP DEFAULT; ALTER TABLE Logs MODIFY Message TEXT NOT NULL; +SELECT 'ALTER TABLE Config MODIFY DefaultValue TEXT'; ALTER TABLE Config MODIFY DefaultValue TEXT; -- -- Add an Id column and make it the primary key of the Filters table -- + +SELECT 'Check for Id column in Filter'; SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS From 43d72decaca48f85a85ee9136bdb31af9bf89ebd Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Jan 2018 18:24:59 -0500 Subject: [PATCH 6/9] Turn off extra debugging --- scripts/ZoneMinder/lib/ZoneMinder/Object.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Object.pm b/scripts/ZoneMinder/lib/ZoneMinder/Object.pm index df7118f0f..0a341fdac 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Object.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Object.pm @@ -48,7 +48,7 @@ use vars qw/ $AUTOLOAD $log $dbh/; *dbh = \$ZoneMinder::Database::dbh; my $debug = 0; -use constant DEBUG_ALL=>1; +use constant DEBUG_ALL=>0; sub new { my ( $parent, $id, $data ) = @_; @@ -170,8 +170,6 @@ sub save { foreach my $k ( keys %$data ) { $log->debug("Object::save after set $k => $$data{$k} $$self{$k}"); } - } else { - $log->debug("No data after set"); } } #$debug = 0; From 6d46a02a9a931f68e6e403f26b20eeced1689aac Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Jan 2018 18:25:24 -0500 Subject: [PATCH 7/9] DbReconnect if the db connection goes down --- scripts/zmstats.pl.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/zmstats.pl.in b/scripts/zmstats.pl.in index 13e643c7a..3ea850ef5 100644 --- a/scripts/zmstats.pl.in +++ b/scripts/zmstats.pl.in @@ -153,7 +153,10 @@ my $eventcounts_week_sth = $dbh->prepare_cached( $eventcounts_week_sql ); my $eventcounts_month_sth = $dbh->prepare_cached( $eventcounts_month_sql ); while( 1 ) { - $dbh->ping(); + while ( ! ( $dbh and $dbh->ping() ) ) { + Info("Reconnecting to db"); + $dbh = zmDbConnect(); + } $dbh->do('DELETE FROM Events_Hour WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 hour)'); $dbh->do('DELETE FROM Events_Day WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 day)'); From bd2da456f425e1d4661dd70f6edc84a616937999 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Jan 2018 21:09:33 -0500 Subject: [PATCH 8/9] handle non-multi-server case when restarting monitors via API --- web/api/app/Controller/MonitorsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/api/app/Controller/MonitorsController.php b/web/api/app/Controller/MonitorsController.php index d06ce1dfe..77113e892 100644 --- a/web/api/app/Controller/MonitorsController.php +++ b/web/api/app/Controller/MonitorsController.php @@ -171,7 +171,7 @@ class MonitorsController extends AppController { $func = $Monitor['Function']; // We don't pass the request data as the monitor object because it may be a subset of the full monitor array $this->daemonControl( $this->Monitor->id, 'stop' ); - if ( ( $func != 'None' ) and ( $Monitor['ServerId'] == ZM_SERVER_ID ) ) { + if ( ( $func != 'None' ) and ( (!defined('ZM_SERVER_ID']) or ($Monitor['ServerId']==ZM_SERVER_ID) ) ) { $this->daemonControl( $this->Monitor->id, 'start' ); } } // end function edit From 181a94de82f7205dcf2c0cb9d960bd5f7ee55e56 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 21 Jan 2018 11:10:34 -0500 Subject: [PATCH 9/9] test for existence of port in url_parts --- web/skins/classic/views/console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/skins/classic/views/console.php b/web/skins/classic/views/console.php index 4bbdf9157..a4731d649 100644 --- a/web/skins/classic/views/console.php +++ b/web/skins/classic/views/console.php @@ -232,7 +232,7 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) { } elseif ( $monitor['Type'] == 'Ffmpeg' || $monitor['Type'] == 'Libvlc' ) { $url_parts = parse_url( $monitor['Path'] ); $source = $url_parts['host']. ( - ( $url_parts['port'] and ( $url_parts['port'] != '554' and $url_parts['port'] != '80' ) ) ? ':'.$url_parts['port'] : '' ); + ( isset($url_parts['port']) and ( $url_parts['port'] != '554' and $url_parts['port'] != '80' ) ) ? ':'.$url_parts['port'] : '' ); } if ( $source == '' ) { $source = 'Monitor ' . $monitor['Id'];