PPU web frontend and dialog box error
Overview
An example that show you how to resume update error of PEAR packages.
For this purpose, and demonstration need, we have forgot to give the channel
of the PEAR package (3rd parameter of factory pattern line 17).
Screenshot


Dependencies
This example requires mandatory resources :
Explains step by step
The PEAR_PackageUpdate package is loaded at line 14,
while on line 17 we instanciate a new web frontend for PPU.
checkUpdate() method on line 27 generate the error
while trying to update the PEAR::DB_DataObject package.
We have two choices to display error on line 38,
depending on first parameter value :
- without context error (default behavior === false or none parameter)
see first screenshot.
- with full context error details : file, line, function class (true as parameter)
see second screenshot.
Source Code
<?php
/**
* An example script that try to update PEAR::DB_DataObject
* using PEAR_PackageUpdate with a Web front end.
*
* @author Laurent Laville
* @package PEAR_PackageUpdate_Web
* @version $Id:$
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @copyright 2006 Laurent Laville
* @ignore
*/
require_once 'PEAR/PackageUpdate.php';
// Create a Web package updater for the DB_DataObject package on the ??? channel.
$ppu = PEAR_PackageUpdate::factory('Web', 'DB_DataObject', '');
// Make sure the updater was created properly.
if ($ppu === false) {
echo "Could not create updater.\n";
echo "You might want to check for and install updates manually.\n";
die();
}
// Check to see if any updates are availble.
if ($ppu->checkUpdate()) {
// If updates are available, present the user with the option to update.
if ($ppu->presentUpdate()) {
// Update the package.
$ppu->update();
$ppu->forceRestart();
}
}
// Check for errors.
if ($ppu->hasErrors()) {
$ppu->errorDialog(true);
}
print 'still alive';
?>