fix spacing and braces
This commit is contained in:
parent
3e35fc24a3
commit
a933d4ae12
|
@ -120,35 +120,28 @@ my $dbh = zmDbConnect();
|
|||
$Config{ZM_DB_USER} = $dbUser;
|
||||
$Config{ZM_DB_PASS} = $dbPass;
|
||||
|
||||
if ( ! ($check || $freshen || $rename || $zoneFix || $migrateEvents || $version) )
|
||||
{
|
||||
if ( $Config{ZM_DYN_DB_VERSION} )
|
||||
{
|
||||
if ( ! ($check || $freshen || $rename || $zoneFix || $migrateEvents || $version) ) {
|
||||
if ( $Config{ZM_DYN_DB_VERSION} ) {
|
||||
$version = $Config{ZM_DYN_DB_VERSION};
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
print( STDERR "Please give a valid option\n" );
|
||||
pod2usage(-exitstatus => -1);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ($check + $freshen + $rename + $zoneFix + $migrateEvents + ($version?1:0)) > 1 )
|
||||
{
|
||||
if ( ($check + $freshen + $rename + $zoneFix + $migrateEvents + ($version?1:0)) > 1 ) {
|
||||
print( STDERR "Please give only one option\n" );
|
||||
pod2usage(-exitstatus => -1);
|
||||
}
|
||||
|
||||
if ( $check && $Config{ZM_CHECK_FOR_UPDATES} )
|
||||
{
|
||||
if ( $check && $Config{ZM_CHECK_FOR_UPDATES} ) {
|
||||
print( "Update agent starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
|
||||
|
||||
my $currVersion = $Config{ZM_DYN_CURR_VERSION};
|
||||
my $lastVersion = $Config{ZM_DYN_LAST_VERSION};
|
||||
my $lastCheck = $Config{ZM_DYN_LAST_CHECK};
|
||||
|
||||
if ( !$currVersion )
|
||||
{
|
||||
if ( !$currVersion ) {
|
||||
$currVersion = $Config{ZM_VERSION};
|
||||
|
||||
my $sql = "update Config set Value = ? where Name = 'ZM_DYN_CURR_VERSION'";
|
||||
|
@ -157,11 +150,9 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} )
|
|||
$sth->finish();
|
||||
}
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
while( 1 ) {
|
||||
my $now = time();
|
||||
if ( !$lastVersion || !$lastCheck || (($now-$lastCheck) > CHECK_INTERVAL) )
|
||||
{
|
||||
if ( !$lastVersion || !$lastCheck || (($now-$lastCheck) > CHECK_INTERVAL) ) {
|
||||
Info( "Checking for updates\n" );
|
||||
|
||||
use LWP::UserAgent;
|
||||
|
@ -173,8 +164,7 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} )
|
|||
my $req = HTTP::Request->new( GET=>'https://update.zoneminder.com/version.txt' );
|
||||
my $res = $ua->request($req);
|
||||
|
||||
if ( $res->is_success )
|
||||
{
|
||||
if ( $res->is_success ) {
|
||||
$lastVersion = $res->content;
|
||||
chomp($lastVersion);
|
||||
$lastCheck = $now;
|
||||
|
@ -190,9 +180,7 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} )
|
|||
my $lc_sth = $dbh->prepare_cached( $lc_sql ) or die( "Can't prepare '$lc_sql': ".$dbh->errstr() );
|
||||
my $lc_res = $lc_sth->execute( $lastCheck ) or die( "Can't execute: ".$lc_sth->errstr() );
|
||||
$lc_sth->finish();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Error( "Error check failed: '".$res->status_line()."'\n" );
|
||||
}
|
||||
}
|
||||
|
@ -200,24 +188,21 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} )
|
|||
}
|
||||
print( "Update agent exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
|
||||
}
|
||||
if ( $rename )
|
||||
{
|
||||
|
||||
if ( $rename ) {
|
||||
require File::Find;
|
||||
|
||||
chdir( EVENT_PATH );
|
||||
|
||||
sub renameImage
|
||||
{
|
||||
sub renameImage {
|
||||
my $file = $_;
|
||||
|
||||
# Ignore directories
|
||||
if ( -d $file )
|
||||
{
|
||||
if ( -d $file ) {
|
||||
print( "Checking directory '$file'\n" );
|
||||
return;
|
||||
}
|
||||
if ( $file !~ /(capture|analyse)-(\d+)(\.jpg)/ )
|
||||
{
|
||||
if ( $file !~ /(capture|analyse)-(\d+)(\.jpg)/ ) {
|
||||
return;
|
||||
}
|
||||
my $newFile = "$2-$1$3";
|
||||
|
@ -228,23 +213,20 @@ if ( $rename )
|
|||
|
||||
File::Find::find( \&renameImage, '.' );
|
||||
}
|
||||
if ( $zoneFix )
|
||||
{
|
||||
if ( $zoneFix ) {
|
||||
|
||||
my $sql = "select Z.*, M.Width as MonitorWidth, M.Height as MonitorHeight from Zones as Z inner join Monitors as M on Z.MonitorId = M.Id where Z.Units = 'Percent'";
|
||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
my @zones;
|
||||
while( my $zone = $sth->fetchrow_hashref() )
|
||||
{
|
||||
while( my $zone = $sth->fetchrow_hashref() ) {
|
||||
push( @zones, $zone );
|
||||
}
|
||||
$sth->finish();
|
||||
|
||||
$sql = "update Zones set MinAlarmPixels = ?, MaxAlarmPixels = ?, MinFilterPixels = ?, MaxFilterPixels = ?, MinBlobPixels = ?, MaxBlobPixels = ? where Id = ?";
|
||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
foreach my $zone ( @zones )
|
||||
{
|
||||
foreach my $zone ( @zones ) {
|
||||
my $zone_width = (($zone->{HiX}*$zone->{MonitorWidth})-($zone->{LoX}*$zone->{MonitorWidth}))/100;
|
||||
my $zone_height = (($zone->{HiY}*$zone->{MonitorHeight})-($zone->{LoY}*$zone->{MonitorHeight}))/100;
|
||||
my $zone_area = $zone_width * $zone_height;
|
||||
|
@ -261,13 +243,11 @@ if ( $zoneFix )
|
|||
}
|
||||
$sth->finish();
|
||||
}
|
||||
if ( $migrateEvents )
|
||||
{
|
||||
if ( $migrateEvents ) {
|
||||
my $webUid = (getpwnam( $Config{ZM_WEB_USER} ))[2];
|
||||
my $webGid = (getgrnam( $Config{ZM_WEB_USER} ))[2];
|
||||
|
||||
if ( !(($> == 0) || ($> == $webUid)) )
|
||||
{
|
||||
if ( !(($> == 0) || ($> == $webUid)) ) {
|
||||
print( "Error, migrating events can only be done as user root or ".$Config{ZM_WEB_USER}.".\n" );
|
||||
exit( -1 );
|
||||
}
|
||||
|
@ -281,32 +261,27 @@ if ( $migrateEvents )
|
|||
print( "\nAbout to convert saved events to deep storage, please ensure that ZoneMinder is fully stopped before proceeding.\nThis process is not easily reversible. Are you sure you wish to proceed?\n\nPress 'y' to continue or 'n' to abort : " );
|
||||
my $response = <STDIN>;
|
||||
chomp( $response );
|
||||
while ( $response !~ /^[yYnN]$/ )
|
||||
{
|
||||
while ( $response !~ /^[yYnN]$/ ) {
|
||||
print( "Please press 'y' to continue or 'n' to abort only : " );
|
||||
$response = <STDIN>;
|
||||
chomp( $response );
|
||||
}
|
||||
|
||||
if ( $response =~ /^[yY]$/ )
|
||||
{
|
||||
if ( $response =~ /^[yY]$/ ) {
|
||||
print( "Converting all events to deep storage.\n" );
|
||||
|
||||
chdir( $Config{ZM_PATH_WEB} );
|
||||
my $sql = "select *, unix_timestamp(StartTime) as UnixStartTime from Events";
|
||||
my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute();
|
||||
if ( !$res )
|
||||
{
|
||||
if ( !$res ) {
|
||||
Fatal( "Can't fetch Events: ".$sth->errstr() );
|
||||
}
|
||||
|
||||
while( my $event = $sth->fetchrow_hashref() )
|
||||
{
|
||||
while( my $event = $sth->fetchrow_hashref() ) {
|
||||
my $oldEventPath = $Config{ZM_DIR_EVENTS}.'/'.$event->{MonitorId}.'/'.$event->{Id};
|
||||
|
||||
if ( !-d $oldEventPath )
|
||||
{
|
||||
if ( !-d $oldEventPath ) {
|
||||
print( "Warning, can't find old event path '$oldEventPath', already converted?\n" );
|
||||
next;
|
||||
}
|
||||
|
@ -330,14 +305,11 @@ if ( $migrateEvents )
|
|||
$sth->finish();
|
||||
|
||||
print( "All events converted.\n\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
print( "Aborting event conversion.\n\n" );
|
||||
}
|
||||
}
|
||||
if ( $freshen )
|
||||
{
|
||||
if ( $freshen ) {
|
||||
print( "\nFreshening configuration in database\n" );
|
||||
ZoneMinder::Config::loadConfigFromDB();
|
||||
ZoneMinder::Config::saveConfigToDB();
|
||||
|
@ -375,22 +347,18 @@ if ( $interactive ) {
|
|||
}
|
||||
} # end if interactive
|
||||
|
||||
if ( $version )
|
||||
{
|
||||
if ( $version ) {
|
||||
my ( $detaint_version ) = $version =~ /^([\w.]+)$/;
|
||||
$version = $detaint_version;
|
||||
|
||||
if ( ZM_VERSION eq $version )
|
||||
{
|
||||
if ( ZM_VERSION eq $version ) {
|
||||
print( "\nDatabase already at version $version, update aborted.\n\n" );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
print( "\nInitiating database upgrade to version ".ZM_VERSION." from version $version\n" );
|
||||
if ( $interactive )
|
||||
{
|
||||
if ( $Config{ZM_DYN_DB_VERSION} && $Config{ZM_DYN_DB_VERSION} ne $version )
|
||||
{
|
||||
if ( $interactive ) {
|
||||
if ( $Config{ZM_DYN_DB_VERSION} && $Config{ZM_DYN_DB_VERSION} ne $version ) {
|
||||
print( "\nWARNING - You have specified an upgrade from version $version but the database version found is ".$Config{ZM_DYN_DB_VERSION}.". Is this correct?\nPress enter to continue or ctrl-C to abort : " );
|
||||
my $response = <STDIN>;
|
||||
}
|
||||
|
@ -401,34 +369,25 @@ if ( $version )
|
|||
print( "\nDo you wish to take a backup of your database prior to upgrading?\nThis may result in a large file in @ZM_TMPDIR@ if you have a lot of events.\nPress 'y' for a backup or 'n' to continue : " );
|
||||
$response = <STDIN>;
|
||||
chomp( $response );
|
||||
while ( $response !~ /^[yYnN]$/ )
|
||||
{
|
||||
while ( $response !~ /^[yYnN]$/ ) {
|
||||
print( "Please press 'y' for a backup or 'n' to continue only : " );
|
||||
$response = <STDIN>;
|
||||
chomp( $response );
|
||||
}
|
||||
|
||||
if ( $response =~ /^[yY]$/ )
|
||||
{
|
||||
if ( $response =~ /^[yY]$/ ) {
|
||||
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
|
||||
my $command = "mysqldump";
|
||||
if ( defined($portOrSocket) )
|
||||
{
|
||||
if ( $portOrSocket =~ /^\// )
|
||||
{
|
||||
if ( defined($portOrSocket) ) {
|
||||
if ( $portOrSocket =~ /^\// ) {
|
||||
$command .= " -S".$portOrSocket;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$command .= " -h".$host." -P".$portOrSocket;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$command .= " -h".$host;
|
||||
}
|
||||
if ( $dbUser )
|
||||
{
|
||||
if ( $dbUser ) {
|
||||
$command .= ' -u'.$dbUser;
|
||||
$command .= ' -p"'.$dbPass.'"' if $dbPass;
|
||||
}
|
||||
|
@ -438,59 +397,42 @@ if ( $version )
|
|||
print( "Executing '$command'\n" ) if ( logDebugging() );
|
||||
my $output = qx($command);
|
||||
my $status = $? >> 8;
|
||||
if ( $status || logDebugging() )
|
||||
{
|
||||
if ( $status || logDebugging() ) {
|
||||
chomp( $output );
|
||||
print( "Output: $output\n" );
|
||||
}
|
||||
if ( $status )
|
||||
{
|
||||
if ( $status ) {
|
||||
die( "Command '$command' exited with status: $status\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
print( "Database successfully backed up to $backup, proceeding to upgrade.\n" );
|
||||
}
|
||||
}
|
||||
elsif ( $response !~ /^[nN]$/ )
|
||||
{
|
||||
} elsif ( $response !~ /^[nN]$/ ) {
|
||||
die( "Unexpected response '$response'" );
|
||||
}
|
||||
}
|
||||
sub patchDB
|
||||
{
|
||||
sub patchDB {
|
||||
my $dbh = shift;
|
||||
my $version = shift;
|
||||
|
||||
my ( $host, $portOrSocket ) = ( $Config{ZM_DB_HOST} =~ /^([^:]+)(?::(.+))?$/ );
|
||||
my $command = "mysql";
|
||||
if ( defined($portOrSocket) )
|
||||
{
|
||||
if ( $portOrSocket =~ /^\// )
|
||||
{
|
||||
if ( defined($portOrSocket) ) {
|
||||
if ( $portOrSocket =~ /^\// ) {
|
||||
$command .= " -S".$portOrSocket;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$command .= " -h".$host." -P".$portOrSocket;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$command .= " -h".$host;
|
||||
}
|
||||
if ( $dbUser )
|
||||
{
|
||||
if ( $dbUser ) {
|
||||
$command .= " -u".$dbUser;
|
||||
$command .= ' -p"'.$dbPass.'"' if $dbPass;
|
||||
}
|
||||
$command .= " ".$Config{ZM_DB_NAME}." < ";
|
||||
if ( $updateDir )
|
||||
{
|
||||
if ( $updateDir ) {
|
||||
$command .= $updateDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$command .= $Config{ZM_PATH_DATA}."/db";
|
||||
}
|
||||
$command .= "/zm_update-".$version.".sql";
|
||||
|
@ -498,17 +440,13 @@ if ( $version )
|
|||
print( "Executing '$command'\n" ) if ( logDebugging() );
|
||||
my $output = qx($command);
|
||||
my $status = $? >> 8;
|
||||
if ( $status || logDebugging() )
|
||||
{
|
||||
if ( $status || logDebugging() ) {
|
||||
chomp( $output );
|
||||
print( "Output: $output\n" );
|
||||
}
|
||||
if ( $status )
|
||||
{
|
||||
if ( $status ) {
|
||||
die( "Command '$command' exited with status: $status\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
print( "\nDatabase successfully upgraded to version $version.\n" );
|
||||
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() );
|
||||
|
@ -524,42 +462,35 @@ if ( $version )
|
|||
ZoneMinder::Config::saveConfigToDB();
|
||||
|
||||
my $cascade = undef;
|
||||
if ( $cascade || $version eq "1.19.0" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.19.0" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.19.0" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.19.1" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.19.1" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.19.1");
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.19.2" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.19.2" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.19.2" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.19.3" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.19.3" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.19.3" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.19.4" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.19.4" ) {
|
||||
# Rename the event directories and create a new symlink for the names
|
||||
chdir( EVENT_PATH );
|
||||
|
||||
my $sql = "select * from Monitors order by Id";
|
||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
while( my $monitor = $sth->fetchrow_hashref() )
|
||||
{
|
||||
if ( -d $monitor->{Name} )
|
||||
{
|
||||
while( my $monitor = $sth->fetchrow_hashref() ) {
|
||||
if ( -d $monitor->{Name} ) {
|
||||
rename( $monitor->{Name}, $monitor->{Id} ) or warn( "Can't rename existing monitor directory '$monitor->{Name}' to '$monitor->{Id}': $!" );
|
||||
symlink( $monitor->{Id}, $monitor->{Name} ) or warn( "Can't symlink monitor directory '$monitor->{Id}' to '$monitor->{Name}': $!" );
|
||||
}
|
||||
|
@ -571,46 +502,39 @@ if ( $version )
|
|||
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.19.5" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.19.5" ) {
|
||||
print( "\nThis version now only uses one database user.\nPlease ensure you have run zmconfig.pl and re-entered your database username and password prior to upgrading, or the upgrade will fail.\nPress enter to continue or ctrl-C to stop : " );
|
||||
# Patch the database
|
||||
my $dummy = <STDIN>;
|
||||
patchDB( $dbh, "1.19.5" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.20.0" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.20.0" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.20.0" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.20.1" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.20.1" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.20.1" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.21.0" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.21.0" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.21.0" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.21.1" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.21.1" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.21.1" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.21.2" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.21.2" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.21.2" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.21.3" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.21.3" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.21.3" );
|
||||
|
||||
|
@ -620,8 +544,7 @@ if ( $version )
|
|||
my $sql = "select * from Monitors order by Id";
|
||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
while( my $monitor = $sth->fetchrow_hashref() )
|
||||
{
|
||||
while( my $monitor = $sth->fetchrow_hashref() ) {
|
||||
my $sql = "update Events set Width = ?, Height = ? where MonitorId = ?";
|
||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute( $monitor->{Width}, $monitor->{Height}, $monitor->{Id} ) or die( "Can't execute: ".$sth->errstr() );
|
||||
|
@ -636,8 +559,7 @@ if ( $version )
|
|||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
my $sequence = 1;
|
||||
while( my $monitor = $sth->fetchrow_hashref() )
|
||||
{
|
||||
while( my $monitor = $sth->fetchrow_hashref() ) {
|
||||
my $sql = "update Monitors set Sequence = ? where Id = ?";
|
||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute( $sequence++, $monitor->{Id} ) or die( "Can't execute: ".$sth->errstr() );
|
||||
|
@ -652,17 +574,14 @@ if ( $version )
|
|||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
my @filters;
|
||||
while( my $filter = $sth->fetchrow_hashref() )
|
||||
{
|
||||
while( my $filter = $sth->fetchrow_hashref() ) {
|
||||
push( @filters, $filter );
|
||||
}
|
||||
$sth->finish();
|
||||
$sql = "update Filters set Query = ? where Name = ?";
|
||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
foreach my $filter ( @filters )
|
||||
{
|
||||
if ( $filter->{Query} =~ /op\d=&/ )
|
||||
{
|
||||
foreach my $filter ( @filters ) {
|
||||
if ( $filter->{Query} =~ /op\d=&/ ) {
|
||||
( my $newQuery = $filter->{Query} ) =~ s/(op\d=)&/$1=&/g;
|
||||
$res = $sth->execute( $newQuery, $filter->{Name} ) or die( "Can't execute: ".$sth->errstr() );
|
||||
}
|
||||
|
@ -671,8 +590,7 @@ if ( $version )
|
|||
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.21.4" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.21.4" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.21.4" );
|
||||
|
||||
|
@ -685,24 +603,19 @@ if ( $version )
|
|||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
my @zones;
|
||||
while( my $zone = $sth->fetchrow_hashref() )
|
||||
{
|
||||
while( my $zone = $sth->fetchrow_hashref() ) {
|
||||
push( @zones, $zone );
|
||||
}
|
||||
$sth->finish();
|
||||
|
||||
no strict 'refs';
|
||||
foreach my $zone ( @zones )
|
||||
{
|
||||
foreach my $zone ( @zones ) {
|
||||
# Create the coordinate strings
|
||||
if ( $zone->{Units} eq "Pixels" )
|
||||
{
|
||||
if ( $zone->{Units} eq "Pixels" ) {
|
||||
my $sql = "update Zones set NumCoords = 4, Coords = concat( LoX,',',LoY,' ',HiX,',',LoY,' ',HiX,',',HiY,' ',LoX,',',HiY ), Area = round( ((HiX-LoX)+1)*((HiY-LoY)+1) ) where Id = ?";
|
||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute( $zone->{Id} ) or die( "Can't execute: ".$sth->errstr() );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
my $loX = ($zone->{LoX} * ($zone->{Width}-1) ) / 100;
|
||||
my $hiX = ($zone->{HiX} * ($zone->{Width}-1) ) / 100;
|
||||
my $loY = ($zone->{LoY} * ($zone->{Height}-1) ) / 100;
|
||||
|
@ -723,17 +636,14 @@ if ( $version )
|
|||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
my @states;
|
||||
while( my $state = $sth->fetchrow_hashref() )
|
||||
{
|
||||
while( my $state = $sth->fetchrow_hashref() ) {
|
||||
push( @states, $state );
|
||||
}
|
||||
$sth->finish();
|
||||
|
||||
foreach my $state ( @states )
|
||||
{
|
||||
foreach my $state ( @states ) {
|
||||
my @new_defns;
|
||||
foreach my $defn ( split( /,/, $state->{Definition} ) )
|
||||
{
|
||||
foreach my $defn ( split( /,/, $state->{Definition} ) ) {
|
||||
push( @new_defns, $defn.":1" );
|
||||
}
|
||||
my $sql = "update States set Definition = ? where Name = ?";
|
||||
|
@ -744,23 +654,19 @@ if ( $version )
|
|||
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.22.0" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.22.0" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.22.0" );
|
||||
|
||||
# Check for maximum FPS setting and update alarm max fps settings
|
||||
{
|
||||
print( "Updating monitors. Please wait.\n" );
|
||||
if ( defined(&ZM_NO_MAX_FPS_ON_ALARM) && &ZM_NO_MAX_FPS_ON_ALARM )
|
||||
{
|
||||
if ( defined(&ZM_NO_MAX_FPS_ON_ALARM) && &ZM_NO_MAX_FPS_ON_ALARM ) {
|
||||
# Update the individual monitor settings to match the previous global one
|
||||
my $sql = "update Monitors set AlarmMaxFPS = NULL";
|
||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
# Update the individual monitor settings to match the previous global one
|
||||
my $sql = "update Monitors set AlarmMaxFPS = MaxFPS";
|
||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
|
@ -770,8 +676,7 @@ if ( $version )
|
|||
{
|
||||
print( "Updating mail configuration. Please wait.\n" );
|
||||
my ( $sql, $sth, $res );
|
||||
if ( defined(&ZM_EMAIL_TEXT) && &ZM_EMAIL_TEXT )
|
||||
{
|
||||
if ( defined(&ZM_EMAIL_TEXT) && &ZM_EMAIL_TEXT ) {
|
||||
my ( $email_subject, $email_body ) = $Config{ZM_EMAIL_TEXT} =~ /subject\s*=\s*"([^\n]*)".*body\s*=\s*"(.*)"?$/ms;
|
||||
$sql = "replace into Config set Id = 0, Name = 'ZM_EMAIL_SUBJECT', Value = '".$email_subject."', Type = 'string', DefaultValue = 'ZoneMinder: Alarm - %MN%-%EI% (%ESM% - %ESA% %EFA%)', Hint = 'string', Pattern = '(?-xism:^(.+)\$)', Format = ' \$1 ', Prompt = 'The subject of the email used to send matching event details', Help = 'This option is used to define the subject of the email that is sent for any events that match the appropriate filters.', Category = 'mail', Readonly = '0', Requires = 'ZM_OPT_EMAIL=1'";
|
||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
|
@ -780,8 +685,7 @@ if ( $version )
|
|||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
$res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
}
|
||||
if ( defined(&ZM_MESSAGE_TEXT) && &ZM_MESSAGE_TEXT )
|
||||
{
|
||||
if ( defined(&ZM_MESSAGE_TEXT) && &ZM_MESSAGE_TEXT ) {
|
||||
my ( $message_subject, $message_body ) = $Config{ZM_MESSAGE_TEXT} =~ /subject\s*=\s*"([^\n]*)".*body\s*=\s*"(.*)"?$/ms;
|
||||
$sql = "replace into Config set Id = 0, Name = 'ZM_MESSAGE_SUBJECT', Value = '".$message_subject."', Type = 'string', DefaultValue = 'ZoneMinder: Alarm - %MN%-%EI%', Hint = 'string', Pattern = '(?-xism:^(.+)\$)', Format = ' \$1 ', Prompt = 'The subject of the message used to send matching event details', Help = 'This option is used to define the subject of the message that is sent for any events that match the appropriate filters.', Category = 'mail', Readonly = '0', Requires = 'ZM_OPT_MESSAGE=1'";
|
||||
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
|
@ -793,20 +697,17 @@ if ( $version )
|
|||
}
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.22.1" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.22.1" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.22.1" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.22.2" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.22.2" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.22.2" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.22.3" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.22.3" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.22.3" );
|
||||
|
||||
|
@ -816,15 +717,12 @@ if ( $version )
|
|||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
my @db_monitors;
|
||||
while( my $db_monitor = $sth->fetchrow_hashref() )
|
||||
{
|
||||
while( my $db_monitor = $sth->fetchrow_hashref() ) {
|
||||
push( @db_monitors, $db_monitor );
|
||||
}
|
||||
$sth->finish();
|
||||
foreach my $db_monitor ( @db_monitors )
|
||||
{
|
||||
if ( $db_monitor->{LabelFormat} =~ /\%\%s/ )
|
||||
{
|
||||
foreach my $db_monitor ( @db_monitors ) {
|
||||
if ( $db_monitor->{LabelFormat} =~ /\%\%s/ ) {
|
||||
$db_monitor->{LabelFormat} =~ s/\%\%s/%N/;
|
||||
$db_monitor->{LabelFormat} =~ s/\%\%s/%Q/;
|
||||
|
||||
|
@ -841,25 +739,20 @@ if ( $version )
|
|||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
my @dbFilters;
|
||||
while( my $dbFilter = $sth->fetchrow_hashref() )
|
||||
{
|
||||
while( my $dbFilter = $sth->fetchrow_hashref() ) {
|
||||
push( @dbFilters, $dbFilter );
|
||||
}
|
||||
$sth->finish();
|
||||
foreach my $dbFilter ( @dbFilters )
|
||||
{
|
||||
foreach my $dbFilter ( @dbFilters ) {
|
||||
my %filter_terms;
|
||||
foreach my $filter_parm ( split( /&/, $dbFilter->{Query} ) )
|
||||
{
|
||||
foreach my $filter_parm ( split( /&/, $dbFilter->{Query} ) ) {
|
||||
my( $key, $value ) = split( /=/, $filter_parm, 2 );
|
||||
if ( $key )
|
||||
{
|
||||
if ( $key ) {
|
||||
$filter_terms{$key} = $value;
|
||||
}
|
||||
}
|
||||
my $filter = { 'terms' => [] };
|
||||
for ( my $i = 1; $i <= $filter_terms{trms}; $i++ )
|
||||
{
|
||||
for ( my $i = 1; $i <= $filter_terms{trms}; $i++ ) {
|
||||
my $term = {};
|
||||
my $conjunction_name = "cnj$i";
|
||||
my $obracket_name = "obr$i";
|
||||
|
@ -882,11 +775,9 @@ if ( $version )
|
|||
|
||||
my $newQuery = 'a:'.int(keys(%$filter)).':{s:5:"terms";a:'.int(@{$filter->{terms}}).':{';
|
||||
my $i = 0;
|
||||
foreach my $term ( @{$filter->{terms}} )
|
||||
{
|
||||
foreach my $term ( @{$filter->{terms}} ) {
|
||||
$newQuery .= 'i:'.$i.';a:'.int(keys(%$term)).':{';
|
||||
while ( my ( $key, $val ) = each( %$term ) )
|
||||
{
|
||||
while ( my ( $key, $val ) = each( %$term ) ) {
|
||||
$newQuery .= 's:'.length($key).':"'.$key.'";';
|
||||
$newQuery .= 's:'.length($val).':"'.$val.'";';
|
||||
}
|
||||
|
@ -894,10 +785,8 @@ if ( $version )
|
|||
$i++;
|
||||
}
|
||||
$newQuery .= '}';
|
||||
foreach my $field ( "sort_field", "sort_asc", "limit" )
|
||||
{
|
||||
if ( defined($filter->{$field}) )
|
||||
{
|
||||
foreach my $field ( "sort_field", "sort_asc", "limit" ) {
|
||||
if ( defined($filter->{$field}) ) {
|
||||
$newQuery .= 's:'.length($field).':"'.$field.'";';
|
||||
$newQuery .= 's:'.length($filter->{$field}).':"'.$filter->{$field}.'";';
|
||||
}
|
||||
|
@ -920,52 +809,43 @@ if ( $version )
|
|||
}
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.23.0" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.23.0" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.23.0" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.23.1" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.23.1" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.23.1" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.23.2" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.23.2" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.23.2" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.23.3" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.23.3" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.23.3" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.24.0" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.24.0" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.24.0" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.24.1" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.24.1" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.24.1" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.24.2" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.24.2" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.24.2" );
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.24.3" )
|
||||
{
|
||||
my $result = eval
|
||||
{
|
||||
if ( $cascade || $version eq "1.24.3" ) {
|
||||
my $result = eval {
|
||||
require PHP::Serialization;
|
||||
PHP::Serialization->import();
|
||||
};
|
||||
|
@ -981,13 +861,11 @@ if ( $version )
|
|||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() );
|
||||
my @dbFilters;
|
||||
while( my $dbFilter = $sth->fetchrow_hashref() )
|
||||
{
|
||||
while( my $dbFilter = $sth->fetchrow_hashref() ) {
|
||||
push( @dbFilters, $dbFilter );
|
||||
}
|
||||
$sth->finish();
|
||||
foreach my $dbFilter ( @dbFilters )
|
||||
{
|
||||
foreach my $dbFilter ( @dbFilters ) {
|
||||
print( " ".$dbFilter->{Name} );
|
||||
eval {
|
||||
my $phpQuery = $dbFilter->{Query};
|
||||
|
@ -997,13 +875,10 @@ if ( $version )
|
|||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute( $jsonQuery, $dbFilter->{Name} ) or die( "Can't execute: ".$sth->errstr() );
|
||||
};
|
||||
if ( $@ )
|
||||
{
|
||||
if ( $@ ) {
|
||||
print( " - failed, please check or report. Query is '".$dbFilter->{Query}."'\n" );
|
||||
print( $@ );
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
print( " - complete\n" );
|
||||
}
|
||||
}
|
||||
|
@ -1011,8 +886,7 @@ if ( $version )
|
|||
}
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version eq "1.24.4" )
|
||||
{
|
||||
if ( $cascade || $version eq "1.24.4" ) {
|
||||
# Patch the database
|
||||
patchDB( $dbh, "1.24.4" );
|
||||
|
||||
|
@ -1022,15 +896,13 @@ if ( $version )
|
|||
my $updateSql = "update Config set Value = ? where Name = ?";
|
||||
my $updateSth = $dbh->prepare_cached( $updateSql ) or die( "Can't prepare '$updateSql': ".$dbh->errstr() );
|
||||
my $fetchRes = $fetchSth->execute() or die( "Can't execute: ".$fetchSth->errstr() );
|
||||
while( my $config = $fetchSth->fetchrow_hashref() )
|
||||
{
|
||||
while( my $config = $fetchSth->fetchrow_hashref() ) {
|
||||
( my $name = $config->{Name} ) =~ s/_FTP_/_/;
|
||||
my $updateRes = $updateSth->execute( $config->{Value}, $name ) or die( "Can't execute: ".$updateSth->errstr() );
|
||||
}
|
||||
$cascade = !undef;
|
||||
}
|
||||
if ( $cascade || $version lt "1.26.0" )
|
||||
{
|
||||
if ( $cascade || $version lt "1.26.0" ) {
|
||||
my $sth = $dbh->prepare_cached( 'select * from Monitors LIMIT 0,1' );
|
||||
die "Error: " . $dbh->errstr . "\n" unless ($sth);
|
||||
die "Error: " . $sth->errstr . "\n" unless ($sth->execute);
|
||||
|
@ -1044,7 +916,6 @@ if ( $version )
|
|||
} # end if
|
||||
$sth->finish();
|
||||
|
||||
|
||||
$cascade = !undef;
|
||||
$version = '1.26.0';
|
||||
}
|
||||
|
@ -1083,17 +954,14 @@ if ( $version )
|
|||
$cascade = !undef;
|
||||
} # end if
|
||||
|
||||
if ( $cascade )
|
||||
{
|
||||
if ( $cascade ) {
|
||||
my $installed_version = ZM_VERSION;
|
||||
my $sql = "update Config set Value = ? where Name = ?";
|
||||
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
my $res = $sth->execute( "$installed_version", "ZM_DYN_DB_VERSION" ) or die( "Can't execute: ".$sth->errstr() );
|
||||
$res = $sth->execute( "$installed_version", "ZM_DYN_CURR_VERSION" ) or die( "Can't execute: ".$sth->errstr() );
|
||||
$sth->finish();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
zmDbDisconnect();
|
||||
die( "Can't find upgrade from version '$version'" );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue