| 1 | # -*- perl -*- | ||
| 2 | |||
| 3 | # | ||
| 4 | # $Id: TBPJobManager.pm,v 1.3 2005/03/22 09:59:50 eserte Exp $ | ||
| 5 | # Author: Slaven Rezic | ||
| 6 | # | ||
| 7 | # Copyright (C) 2004 Slaven Rezic. All rights reserved. | ||
| 8 | # This package is free software; you can redistribute it and/or | ||
| 9 | # modify it under the same terms as Perl itself. | ||
| 10 | # | ||
| 11 | # Mail: slaven@rezic.de | ||
| 12 | # WWW: http://www.rezic.de/eserte/ | ||
| 13 | # | ||
| 14 | |||
| 15 | package WebEditor::OldController::TBPJobManager; | ||
| 16 | |||
| 17 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 1 | ▶ | use vars qw($VERSION); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | $VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/); | ||
| 20 | |||
| 21 | 1 | ▶ | use base qw(Class::Accessor); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | __PACKAGE__->mk_accessors(qw(AJM Controller DBFile DB)); | ||
| 23 | |||
| 24 | 1 | ▶ | use MLDBM; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | 1 | ▶ | use Data::Dumper; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | 0 | ▶ | use DB_File::Lock; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 27 | |||
| 28 | use WE::Util::AtJobManager; | ||
| 29 | |||
| 30 | =head1 NAME | ||
| 31 | |||
| 32 | WebEditor::OldController::TBPJobManager - manager for time based publishing jobs | ||
| 33 | |||
| 34 | =cut | ||
| 35 | |||
| 36 | sub new { | ||
| 37 | my($class, $ctrl) = @_; | ||
| 38 | my $self = bless {}, $class; | ||
| 39 | $self->AJM (WE::Util::AtJobManager->new(queue => "w")); | ||
| 40 | $self->Controller($ctrl); | ||
| 41 | $self->DBFile ($ctrl->Root->RootDir . "/tbp.db"); | ||
| 42 | $self->open_db; | ||
| 43 | $self; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub open_db { | ||
| 47 | my $self = shift; | ||
| 48 | local $MLDBM::Serializer = "Data::Dumper"; | ||
| 49 | local $MLDBM::UseDB = "DB_File::Lock"; | ||
| 50 | tie my %db, "MLDBM", $self->DBFile, O_RDWR|O_CREAT, 0644, $DB_File::DB_HASH, "write" | ||
| 51 | or die "Can't tie to " . $self->DBFile . ": $!"; | ||
| 52 | $self->DB(\%db); | ||
| 53 | } | ||
| 54 | |||
| 55 | sub synchronize_at_jobs { | ||
| 56 | my $self = shift; | ||
| 57 | |||
| 58 | my $ctrl = $self->Controller; | ||
| 59 | my $objdb = $ctrl->Root->ObjDB; | ||
| 60 | my(%to_events, %te_events); | ||
| 61 | $objdb->walk($objdb->root_object->Id, sub { | ||
| 62 | my $id = shift; | ||
| 63 | my $obj = $objdb->get_object($id); | ||
| 64 | if ($obj->TimeOpen) { | ||
| 65 | push @{ $to_events{$obj->TimeOpen} }, [$id, $obj->Title]; | ||
| 66 | } | ||
| 67 | if ($obj->TimeExpire) { | ||
| 68 | push @{ $to_events{$obj->TimeExpire} }, [$id, $obj->Title]; | ||
| 69 | } | ||
| 70 | }); | ||
| 71 | |||
| 72 | my %done_events; # Events done since the last visit. Will be deleted after presenting them. | ||
| 73 | my %new_events; # New events to be inserted in the queue | ||
| 74 | my %expired_events; # Events which are expired , %new_events, | ||
| 75 | # %pend | ||
| 76 | } | ||
| 77 | |||
| 78 | 1; | ||
| 79 | |||
| 80 | __END__ | ||