[vhffs-dev] [2019] Reworked Vhffs::Cron (and also fixed mistakes in others ;P) |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 2019
Author: gradator
Date: 2012-02-18 21:32:49 +0100 (Sat, 18 Feb 2012)
Log Message:
-----------
Reworked Vhffs::Cron (and also fixed mistakes in others ;P)
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Services/Bazaar.pm
trunk/vhffs-api/src/Vhffs/Services/Cron.pm
trunk/vhffs-api/src/Vhffs/Services/Git.pm
trunk/vhffs-api/src/Vhffs/Services/Mercurial.pm
trunk/vhffs-api/src/Vhffs/Services/Repository.pm
trunk/vhffs-api/src/Vhffs/Services/Svn.pm
Modified: trunk/vhffs-api/src/Vhffs/Services/Bazaar.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Bazaar.pm 2012-02-18 19:54:24 UTC (rev 2018)
+++ trunk/vhffs-api/src/Vhffs/Services/Bazaar.pm 2012-02-18 20:32:49 UTC (rev 2019)
@@ -91,7 +91,7 @@
};
if($@) {
- warn "Unable to create bazaar repository $rname: $@\n";
+ warn 'Unable to create bazaar repository '.$rname.': '.$@."\n";
$dbh->rollback;
}
Modified: trunk/vhffs-api/src/Vhffs/Services/Cron.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Cron.pm 2012-02-18 19:54:24 UTC (rev 2018)
+++ trunk/vhffs-api/src/Vhffs/Services/Cron.pm 2012-02-18 20:32:49 UTC (rev 2019)
@@ -2,31 +2,31 @@
# Copyright (c) vhffs project and its contributors
# All rights reserved.
#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
# are met:
#
-# 1. Redistributions of source code must retain the above copyright
+# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in
-# the documentation and/or other materials provided with the
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
# distribution.
-# 3. Neither the name of vhffs nor the names of its contributors
-# may be used to endorse or promote products derived from this
+# 3. Neither the name of vhffs nor the names of its contributors
+# may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# This file is a part of VHFFS4 Hosting Platform
@@ -55,22 +55,27 @@
use base qw(Vhffs::Object);
use Vhffs::Group;
-sub check_cronpath($)
-{
+sub check_cronpath($) {
my $name = shift;
return ($name =~ /^\/[a-z0-9]+\/[a-z0-9]+\/[a-zA-Z0-9\.\_\-\/]+$/);
}
-sub delete
-{
- my $self = shift;
- return unless defined $self;
+sub _new {
+ my ($class, $main, $cron_id, $cronpath, $interval, $reportmail, $lastrundate, $lastrunreturncode, $nextrundate, $running, $owner_uid, $owner_gid, $oid, $date_creation, $description, $state) = @_;
- my $dbh = $self->get_db_object();
- $dbh->do(q{DELETE FROM vhffs_cron WHERE object_id=?}, undef, $self->get_oid()) or return -1;
-
- return -2 if( $self->SUPER::delete < 0 );
- return 1;
+ my $self = $class->SUPER::_new($main, $oid, $owner_uid, $owner_gid, $date_creation, $description, '', $state, Vhffs::Constants::TYPE_CRON);
+ return undef unless(defined $self);
+
+ $self->{cron_id} = $cron_id;
+ $self->{cronpath} = $cronpath;
+ $self->{interval} = $interval;
+ $self->{reportmail} = $reportmail;
+ $self->{lastrundate} = $lastrundate;
+ $self->{lastrunreturncode} = $lastrunreturncode;
+ $self->{nextrundate} = $nextrundate;
+ $self->{running} = $running;
+
+ return $self;
}
=pod
@@ -84,9 +89,7 @@
fully functional object.
=cut
-
-sub create
-{
+sub create {
my ($main, $cronpath, $interval, $reportmail, $description, $user, $group, ) = @_;
return undef unless ( defined $cronpath && defined $interval && defined $reportmail && defined $user && defined $group );
@@ -115,43 +118,18 @@
};
if($@) {
- warn "Unable to create cron job $cronpath: $@\n";
+ warn 'Unable to create cron job '.$cronpath.': '.$@."\n";
$dbh->rollback;
}
return $cron;
}
-=pod
-
-=head2 get_by_cronpath
-
- my $repo = Vhffs::Services::Cron::get_by_cronpath($main, $path);
- die('Cron not found') unless(defined $path);
-
-Fetches an existing cron job.
-
-=cut
-
-sub get_by_cronpath($$) {
- my ($main, $path) = @_;
-
- my @params;
-
- my $sql = 'SELECT c.cron_id, c.cronpath, c.interval, c.reportmail, c.lastrundate, c.lastrunreturncode, c.nextrundate, c.running, o.owner_uid, o.owner_gid, o.object_id, o.date_creation, o.description, o.state FROM vhffs_cron c INNER JOIN vhffs_object o ON o.object_id = c.object_id WHERE c.cronpath = ?';
-
- my $dbh = $main->get_db_object();
- return undef unless(@params = $dbh->selectrow_array($sql, undef, $path));
-
- return _new Vhffs::Services::Cron($main, @params);
-}
-
=head2 fill_object
See C<Vhffs::Object::fill_object
=cut
-
sub fill_object {
my ($class, $obj) = @_;
my $sql = q{SELECT cron_id, cronpath, interval, reportmail, lastrundate, lastrunreturncode, nextrundate, running
@@ -159,60 +137,28 @@
return $class->SUPER::_fill_object($obj, $sql);
}
-sub _new {
- my ($class, $main, $cron_id, $cronpath, $interval, $reportmail, $lastrundate, $lastrunreturncode, $nextrundate, $running, $owner_uid, $owner_gid, $oid, $date_creation, $description, $state) = @_;
-
- my $self = $class->SUPER::_new($main, $oid, $owner_uid, $owner_gid, $date_creation, $description, '', $state, Vhffs::Constants::TYPE_CRON);
- return undef unless(defined $self);
-
- $self->{cron_id} = $cron_id;
- $self->{cronpath} = $cronpath;
- $self->{interval} = $interval;
- $self->{reportmail} = $reportmail;
- $self->{lastrundate} = $lastrundate;
- $self->{lastrunreturncode} = $lastrunreturncode;
- $self->{nextrundate} = $nextrundate;
- $self->{running} = $running;
-
- return $self;
-}
-
-sub commit
-{
- my $self = shift;
-
- my $query = 'UPDATE vhffs_cron SET interval=?, reportmail=?, lastrundate=?, lastrunreturncode=?, nextrundate=?, running=? WHERE cron_id=?';
-
- my $request = $self->{'db'}->prepare($query);
- $request->execute( $self->{'interval'} , $self->{'reportmail'} , $self->{'lastrundate'} , $self->{'lastrunreturncode'} , $self->{'nextrundate'} , $self->{'running'} , $self->{'cron_id'} ) or return -1;
-
- return -2 if( $self->SUPER::commit < 0 );
- return 1;
-}
-
-
-sub getall
-{
+sub getall {
my ($vhffs, $state, $path, $group) = @_;
my $repos = [];
my @params;
- my $sql = 'SELECT c.cron_id, c.cronpath, c.interval, c.reportmail, c.lastrundate, c.lastrunreturncode, c.nextrundate, c.running, o.owner_uid, o.owner_gid, o.object_id, o.date_creation, o.description, o.state FROM vhffs_cron c, vhffs_object o WHERE c.object_id = o.object_id';
+ my $sql = 'SELECT c.cron_id, c.cronpath, c.interval, c.reportmail, c.lastrundate, c.lastrunreturncode, c.nextrundate, c.running, o.owner_uid, o.owner_gid, o.object_id, o.date_creation, o.description, o.state FROM vhffs_cron c
+ INNER JOIN vhffs_object o ON c.object_id = o.object_id WHERE 1=1';
if(defined($state)) {
$sql .= ' AND o.state = ?';
push(@params, $state);
}
if(defined $path) {
- $sql .= ' AND c.cronpath = ?';
- push(@params, $path);
+ $sql .= ' AND c.cronpath LIKE ?';
+ push(@params, '%'.$path.'%');
}
if(defined($group)) {
$sql .= ' AND o.owner_gid = ?';
push(@params, $group->get_gid);
}
$sql .= ' ORDER BY c.cronpath';
-
+
my $dbh = $vhffs->get_db_object();
my $sth = $dbh->prepare($sql);
$sth->execute(@params) or return undef;
@@ -223,7 +169,52 @@
return $repos;
}
+=pod
+=head2 get_by_cronpath
+
+ my $repo = Vhffs::Services::Cron::get_by_cronpath($main, $path);
+ die('Cron not found') unless(defined $path);
+
+Fetches an existing cron job.
+
+=cut
+sub get_by_cronpath($$) {
+ my ($main, $path) = @_;
+
+ my @params;
+
+ my $sql = 'SELECT c.cron_id, c.cronpath, c.interval, c.reportmail, c.lastrundate, c.lastrunreturncode, c.nextrundate, c.running, o.owner_uid, o.owner_gid, o.object_id, o.date_creation, o.description, o.state FROM vhffs_cron c
+ INNER JOIN vhffs_object o ON o.object_id = c.object_id WHERE c.cronpath = ?';
+
+ my $dbh = $main->get_db_object();
+ return undef unless(@params = $dbh->selectrow_array($sql, undef, $path));
+
+ return _new Vhffs::Services::Cron($main, @params);
+}
+
+sub delete {
+ my $self = shift;
+ return unless defined $self;
+
+ my $dbh = $self->get_db_object();
+ $dbh->do(q{DELETE FROM vhffs_cron WHERE object_id=?}, undef, $self->get_oid()) or return -1;
+
+ return $self->SUPER::delete;
+}
+
+sub commit {
+ my $self = shift;
+
+ my $query = 'UPDATE vhffs_cron SET interval=?, reportmail=?, lastrundate=?, lastrunreturncode=?, nextrundate=?, running=? WHERE cron_id=?';
+
+ my $request = $self->{'db'}->prepare($query);
+ $request->execute( $self->{'interval'} , $self->{'reportmail'} , $self->{'lastrundate'} , $self->{'lastrunreturncode'} , $self->{'nextrundate'} , $self->{'running'} , $self->{'cron_id'} ) or return -1;
+
+ return -2 if( $self->SUPER::commit < 0 );
+ return 1;
+}
+
sub get_cron_id {
my $self = shift;
return $self->{'cron_id'};
@@ -239,46 +230,31 @@
return $self->{'cronpath'};
}
-sub get_name
-{
+sub get_name {
my $self = shift;
return $self->{'cronpath'};
}
-sub set_name
-{
- my ($self , $value) = @_;
- if( check_cronpath($value) ) {
- $self->{'cronpath'} = $value;
- return 0;
- }
- return 1;
-}
-
-sub get_interval
-{
+sub get_interval {
my $self = shift;
return $self->{'interval'};
}
-sub set_interval
-{
- my ($self , $value) = @_;
+sub set_interval {
+ my ($self, $value) = @_;
my $mininterval = $self->get_main->get_config->get_service('cron')->{'minimum_interval'}*60;
$value = $mininterval if( $value < $mininterval );
$self->{'interval'} = $value;
return 0;
}
-sub get_reportmail
-{
+sub get_reportmail {
my $self = shift;
return $self->{'reportmail'};
}
-sub set_reportmail
-{
- my ($self , $value) = @_;
+sub set_reportmail {
+ my ($self, $value) = @_;
if( $value eq '' || Vhffs::Functions::valid_mail($value) ) {
$self->{'reportmail'} = $value;
return 0;
@@ -286,15 +262,13 @@
return 1;
}
-sub get_lastrundate
-{
+sub get_lastrundate {
my $self = shift;
return $self->{'lastrundate'};
}
-sub set_lastrundate
-{
- my ($self , $value) = @_;
+sub set_lastrundate {
+ my ($self, $value) = @_;
if( $value =~ /^\d+$/ ) {
$self->{'lastrundate'} = $value;
return 0;
@@ -302,15 +276,13 @@
return 1;
}
-sub get_lastrunreturncode
-{
+sub get_lastrunreturncode {
my $self = shift;
return $self->{'lastrunreturncode'};
}
-sub set_lastrunreturncode
-{
- my ($self , $value) = @_;
+sub set_lastrunreturncode {
+ my ($self, $value) = @_;
if( $value =~ /^\d+$/ ) {
$self->{'lastrunreturncode'} = $value;
return 0;
@@ -318,15 +290,13 @@
return 1;
}
-sub get_nextrundate
-{
+sub get_nextrundate {
my $self = shift;
return $self->{'nextrundate'};
}
-sub set_nextrundate
-{
- my ($self , $value) = @_;
+sub set_nextrundate {
+ my ($self, $value) = @_;
if( $value =~ /^\d+$/ ) {
$self->{'nextrundate'} = $value;
return 0;
@@ -334,15 +304,13 @@
return 1;
}
-sub get_running
-{
+sub get_running {
my $self = shift;
return $self->{'running'};
}
-sub set_running
-{
- my ($self , $value) = @_;
+sub set_running {
+ my ($self, $value) = @_;
if( $value =~ /^\d+$/ ) {
$self->{'running'} = $value;
return 0;
@@ -350,33 +318,29 @@
return 1;
}
-sub quick_set_running
-{
- my ($self , $value) = @_;
- return undef unless( $value =~ /^\d+$/ );
+sub quick_set_running {
+ my ($self, $value) = @_;
+ return undef unless $value =~ /^\d+$/;
my $query = 'UPDATE vhffs_cron SET running=? WHERE cron_id=?';
my $request = $self->{'db'}->prepare($query);
return $request->execute( $value , $self->{'cron_id'} );
}
-sub quick_inc_running
-{
+sub quick_inc_running {
my $self = shift;
my $query = 'UPDATE vhffs_cron SET running=running+1 WHERE cron_id=?';
my $request = $self->{'db'}->prepare($query);
return $request->execute( $self->{'cron_id'} );
}
-sub quick_dec_running
-{
+sub quick_dec_running {
my $self = shift;
my $query = 'UPDATE vhffs_cron SET running=running-1 WHERE cron_id=?';
my $request = $self->{'db'}->prepare($query);
return $request->execute( $self->{'cron_id'} );
}
-sub quick_get_running
-{
+sub quick_get_running {
my $self = shift;
my $query = 'SELECT running FROM vhffs_cron WHERE cron_id=?';
my $request = $self->{'db'}->prepare($query);
@@ -385,33 +349,29 @@
return $r[0];
}
-sub quick_set_nextrundate
-{
+sub quick_set_nextrundate {
my ($self , $value) = @_;
- return undef unless( $value =~ /^\d+$/ );
+ return undef unless $value =~ /^\d+$/;
my $query = 'UPDATE vhffs_cron SET nextrundate=? WHERE cron_id=?';
my $request = $self->{'db'}->prepare($query);
return $request->execute( $value , $self->{'cron_id'} );
}
-sub quick_set_lastrun
-{
+sub quick_set_lastrun {
my ($self , $date, $returncode) = @_;
- return undef unless ( $date =~ /^\d+$/ && $returncode =~ /^\d+$/ );
+ return undef unless $date =~ /^\d+$/ and $returncode =~ /^\d+$/;
my $query = 'UPDATE vhffs_cron SET lastrundate=?, lastrunreturncode=? WHERE cron_id=?';
my $request = $self->{'db'}->prepare($query);
return $request->execute( $date , $returncode , $self->{'cron_id'} );
}
-sub quick_reset
-{
+sub quick_reset {
my ($self) = @_;
my $query = 'UPDATE vhffs_cron SET running=0, lastrundate=NULL, lastrunreturncode=NULL WHERE cron_id=?';
my $request = $self->{'db'}->prepare($query);
return $request->execute( $self->{'cron_id'} );
}
-
1;
__END__
Modified: trunk/vhffs-api/src/Vhffs/Services/Git.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Git.pm 2012-02-18 19:54:24 UTC (rev 2018)
+++ trunk/vhffs-api/src/Vhffs/Services/Git.pm 2012-02-18 20:32:49 UTC (rev 2019)
@@ -92,7 +92,7 @@
};
if($@) {
- warn "Unable to create git repository $rname: $@\n";
+ warn 'Unable to create git repository '.$rname.': '.$@."\n";
$dbh->rollback;
}
Modified: trunk/vhffs-api/src/Vhffs/Services/Mercurial.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Mercurial.pm 2012-02-18 19:54:24 UTC (rev 2018)
+++ trunk/vhffs-api/src/Vhffs/Services/Mercurial.pm 2012-02-18 20:32:49 UTC (rev 2019)
@@ -91,7 +91,7 @@
};
if($@) {
- warn "Unable to create mercurial repository $rname: $@\n";
+ warn 'Unable to create mercurial repository '.$rname.': '.$@."\n";
$dbh->rollback;
}
Modified: trunk/vhffs-api/src/Vhffs/Services/Repository.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Repository.pm 2012-02-18 19:54:24 UTC (rev 2018)
+++ trunk/vhffs-api/src/Vhffs/Services/Repository.pm 2012-02-18 20:32:49 UTC (rev 2019)
@@ -235,13 +235,6 @@
return $self->{'name'};
}
-sub set_name
-{
- my ($self , $value) = @_;
- $self->{'name'} = $value;
-}
-
-
sub get_quota
{
my $self = shift;
Modified: trunk/vhffs-api/src/Vhffs/Services/Svn.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Svn.pm 2012-02-18 19:54:24 UTC (rev 2018)
+++ trunk/vhffs-api/src/Vhffs/Services/Svn.pm 2012-02-18 20:32:49 UTC (rev 2019)
@@ -93,7 +93,7 @@
};
if($@) {
- warn "Unable to create svn repository $rname: $@\n";
+ warn 'Unable to create svn repository '.$rname.': '.$@."\n";
$dbh->rollback;
}
- Messages sorted by: [ date | thread ]
- Prev by Date:
[vhffs-dev] [2018] Reworked Services::Cvs, Services::Svn, Services::Git, Services:: Mercurial, Services::Bazaar
- Next by Date:
[vhffs-dev] [2020] Reworked Vhffs::Services::DNS, removed all Vhffs::Services::delete
- Previous by thread:
[vhffs-dev] [2018] Reworked Services::Cvs, Services::Svn, Services::Git, Services:: Mercurial, Services::Bazaar
- Next by thread:
[vhffs-dev] [2020] Reworked Vhffs::Services::DNS, removed all Vhffs::Services::delete