Apache-Voodoo

 view release on metacpan or  search on metacpan

lib/Apache/Voodoo/Install/Updater.pm  view on Meta::CPAN

###############################################################################
#
# Apache::Voodoo::Install::Updater - Update xml processor
#
# This package provides the internal methods use by voodoo-control that do
# pre/post/upgrade commands as specified by the various .xml files in an
# application.  It's not intended to be use directly by end users.
#
###############################################################################
package Apache::Voodoo::Install::Updater;

$VERSION = "3.0200";

use strict;
use warnings;

use base("Apache::Voodoo::Install");

use Apache::Voodoo::Constants;

use CPAN;
use DBI;
use Digest::MD5;
use Sys::Hostname;
use XML::Checker::Parser;
use File::Find;
use Config::General qw(ParseConfig);

# make CPAN download dependancies
$CPAN::Config->{'prerequisites_policy'} = 'follow';

################################################################################
# Creates a new updater object with given configuration options.  It assumes
# that the files for the application have already been installed or exist in
# appropriate location.  A good database security setup would not allow the
# user the application connects as to have alter, create or drop privileges; thus
# the need for the database root password.  If pretend is set to a true value,
# the operations are stepped through, but nothing actually happens.
#
# usage:
#    Apache::Voodoo::Install::Updater->new(
#		dbroot   => $database_root_password,
#		app_name => $application_name,
#		verbose  => $output_verbosity_level,
#		pretend  => $boolean
#	);
################################################################################
sub new {
	my $class = shift;
	my %params = @_;

	my $self = {%params};

	my $ac = Apache::Voodoo::Constants->new();
	$self->{'_md5_'} = Digest::MD5->new;

	$self->{'install_path'} = $ac->install_path()."/".$self->{'app_name'};

	$self->{'conf_file'}    = $self->{'install_path'}."/".$ac->conf_file();
	$self->{'conf_path'}    = $self->{'install_path'}."/".$ac->conf_path();
	$self->{'updates_path'} = $self->{'install_path'}."/".$ac->updates_path();
	$self->{'apache_uid'}   = $ac->apache_uid();
	$self->{'apache_gid'}   = $ac->apache_gid();

	unless (-e $self->{'conf_file'}) {
		die "Can't open configuration file: $self->{'conf_file'}\n";
	}

	bless $self, $class;

	return $self;
}

# Causes the update chain to execute:  pre-setup.xml, unapplied updates, post-setup.xml
sub do_update      { $_[0]->_do_all(0); }

# Causes the new install chain to execute:  pre-setup.xml, setup.xml,
# post-setup.xml, mark all updates applied.  If this is executed on an
# existing system, Bad Things(tm) can happen depending on what commands
# are present in setup.xml
sub do_new_install { $_[0]->_do_all(1); }

# Wizard mode function.  This performs a replace into on the _updates table
# of a system to have entries and correct checksums for each update file
# without actually executing them.  If something went wrong with an install or
# upgrade and manual tinkering was required to get things back in order, this
# method can be used to ensure that the _updates table appears current.
sub mark_updates_applied {
	my $self = shift;

	my %conf = ParseConfig($self->{'conf_file'});

	$self->mesg("- Connection to database");
	$self->{'dbh'} = DBI->connect($conf{'database'}->{'connect'},'root',$self->{'dbroot'}) || die DBI->errstr;

	$self->mesg("- Looking for update command xml files");

	$self->_record_updates($self->_find_updates());

	$self->mesg("- All updates marked as applied");
}



( run in 1.243 second using v1.01-cache-2.11-cpan-d8267643d1d )