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

sample screenshot

sample 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 :

Source Code

  1. <?php
  2. /**
  3. * An example script that try to update PEAR::DB_DataObject
  4. * using PEAR_PackageUpdate with a Web front end.
  5. *
  6. * @author    Laurent Laville
  7. * @package   PEAR_PackageUpdate_Web
  8. * @version   $Id:$
  9. * @license   http://www.php.net/license/3_01.txt  PHP License 3.01
  10. * @copyright 2006 Laurent Laville
  11. * @ignore
  12. */
  13.  
  14. require_once 'PEAR/PackageUpdate.php';
  15.  
  16. // Create a Web package updater for the DB_DataObject package on the ??? channel.
  17. $ppu = PEAR_PackageUpdate::factory('Web', 'DB_DataObject', '');
  18.  
  19. // Make sure the updater was created properly.
  20. if ($ppu === false) {
  21.     echo "Could not create updater.\n";
  22.     echo "You might want to check for and install updates manually.\n";
  23.     die();
  24. }
  25.  
  26. // Check to see if any updates are availble.
  27. if ($ppu->checkUpdate()) {
  28.     // If updates are available, present the user with the option to update.
  29.     if ($ppu->presentUpdate()) {
  30.         // Update the package.
  31.         $ppu->update();
  32.         $ppu->forceRestart();
  33.     }
  34. }
  35.  
  36. // Check for errors.
  37. if ($ppu->hasErrors()) {
  38.     $ppu->errorDialog(true);
  39. }
  40.  
  41. print 'still alive';
  42. ?>