PPU without frontend
Overview
Always keep your application up-to-date with the most recent and stable version
of PEAR packages.
This example implement the communication with pear channel and the Log package.
Screenshot
Once download operation is completed and update succeeded with pear installer,
the page will be display again and print "Hello World"
Dependencies
This example requires mandatory resources :
Explains step by step
This example will simulate an application that used the PEAR::Log package we try
to keep up-to-date.
The PEAR::Log package is loaded at line 13, and of course
PPU at line line 14.
On lines 20-37 we defined a null frontend that allow
to keep your application ressources up-to-date without asking end-user inputs.
This null frontend is instanciated at line 40 where
we ask to check for update on pear channel for Log package.
On lines 25-26 we set preferences to check for any
next stable version.
forceRestart method defined on lines 20 to 36
and lines 45;50 allow to
reload the current script/page with new version of PEAR::Log package and consume
all messages given by the pear installer.
Source Code
<?php
/**
* Always keep your application up-to-date with the most recent and stable version
* of PEAR::Log package.
*
* @version $Id: withoutFrontend.php,v 1.1 2006/05/07 18:14:09 farell Exp $
* @author Laurent Laville <pear@laurent-laville.org>
* @package PEAR_PackageUpdate
* @access public
* @since File available since Release 0.5.0
*/
require_once 'Log.php';
require_once 'PEAR/PackageUpdate.php';
/**
* This class allow to use PEAR_PackageUpdate as backend without any frontend.
* No end-user action needed.
*/
class PEAR_PackageUpdate_Null extends PEAR_PackageUpdate
{
function PEAR_PackageUpdate_Null($packageName, $channel)
{
parent::PEAR_PackageUpdate($packageName, $channel);
$this->setMinimumState(PEAR_PACKAGEUPDATE_STATE_STABLE);
$this->setMinimumReleaseType(PEAR_PACKAGEUPDATE_TYPE_BUG);
}
function forceRestart()
{
// removes warning message given by pear installer
ob_end_clean();
// Reload current page.
header('Location: ' . $_SERVER['PHP_SELF']);
exit();
}
}
// Check for updates of PEAR::Log package though pear.php.net channel
$ppu =& PEAR_PackageUpdate::factory('Null', 'Log', 'pear');
if ($ppu !== false) {
// Check for new stable version
if ($ppu->checkUpdate()) {
// Update your local copy
ob_start();
if ($ppu->update()) {
// If the update succeeded, the application should be restarted.
$ppu->forceRestart();
}
ob_end_clean();
}
}
// your application code goes here ...
print 'Hello World';
?>