PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/blog/www/system/library/PEAR/PEAR/Installer/Role/Cfg.php

https://bitbucket.org/vmihailenco/vladimirwebdev
PHP | 108 lines | 56 code | 2 blank | 50 comment | 12 complexity | da86fc70dd2b114bb7739dcf55f124a7 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * PEAR_Installer_Role_Cfg
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * LICENSE: This source file is subject to version 3.0 of the PHP license
  8. * that is available through the world-wide-web at the following URI:
  9. * http://www.php.net/license/3_0.txt. If you did not receive a copy of
  10. * the PHP License and are unable to obtain it through the web, please
  11. * send a note to license@php.net so we can mail you a copy immediately.
  12. *
  13. * @category pear
  14. * @package PEAR
  15. * @author Greg Beaver <cellog@php.net>
  16. * @copyright 2007-2008 The PHP Group
  17. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  18. * @version CVS: $Id: Cfg.php 11 2008-09-16 18:31:09Z root $
  19. * @link http://pear.php.net/package/PEAR
  20. * @since File available since Release 1.7.0
  21. */
  22. /**
  23. * @category pear
  24. * @package PEAR
  25. * @author Greg Beaver <cellog@php.net>
  26. * @copyright 2007-2008 The PHP Group
  27. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  28. * @version Release: 1.7.2
  29. * @link http://pear.php.net/package/PEAR
  30. * @since Class available since Release 1.7.0
  31. */
  32. class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common
  33. {
  34. /**
  35. * @var PEAR_Installer
  36. */
  37. var $installer;
  38. /**
  39. * the md5 of the original file
  40. *
  41. * @var unknown_type
  42. */
  43. var $md5 = null;
  44. /**
  45. * Do any unusual setup here
  46. * @param PEAR_Installer
  47. * @param PEAR_PackageFile_v2
  48. * @param array file attributes
  49. * @param string file name
  50. */
  51. function setup(&$installer, $pkg, $atts, $file)
  52. {
  53. $this->installer = &$installer;
  54. $reg = &$this->installer->config->getRegistry();
  55. $package = $reg->getPackage($pkg->getPackage(), $pkg->getChannel());
  56. if ($package) {
  57. $filelist = $package->getFilelist();
  58. if (isset($filelist[$file]) && isset($filelist[$file]['md5sum'])) {
  59. $this->md5 = $filelist[$file]['md5sum'];
  60. }
  61. }
  62. }
  63. function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
  64. {
  65. $test = parent::processInstallation($pkg, $atts, $file, $tmp_path, $layer);
  66. if (@file_exists($test[2]) && @file_exists($test[3])) {
  67. $md5 = md5_file($test[2]);
  68. // configuration has already been installed, check for mods
  69. if ($md5 !== $this->md5 && $md5 !== md5_file($test[3])) {
  70. // configuration has been modified, so save our version as
  71. // configfile-version
  72. $old = $test[2];
  73. $test[2] .= '.new-' . $pkg->getVersion();
  74. // backup original and re-install it
  75. PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  76. $tmpcfg = $this->config->get('temp_dir');
  77. $newloc = System::mkdir(array('-p', $tmpcfg));
  78. if (!$newloc) {
  79. // try temp_dir
  80. $newloc = System::mktemp(array('-d'));
  81. if (!$newloc || PEAR::isError($newloc)) {
  82. PEAR::popErrorHandling();
  83. return PEAR::raiseError('Could not save existing configuration file '.
  84. $old . ', unable to install. Please set temp_dir ' .
  85. 'configuration variable to a writeable location and try again');
  86. }
  87. } else {
  88. $newloc = $tmpcfg;
  89. }
  90. $temp_file = $newloc . DIRECTORY_SEPARATOR . uniqid('savefile');
  91. if (!@copy($old, $temp_file)) {
  92. PEAR::popErrorHandling();
  93. return PEAR::raiseError('Could not save existing configuration file '.
  94. $old . ', unable to install. Please set temp_dir ' .
  95. 'configuration variable to a writeable location and try again');
  96. }
  97. PEAR::popErrorHandling();
  98. $this->installer->log(0, "WARNING: configuration file $old is being installed as $test[2], you should manually merge in changes to the existing configuration file");
  99. $this->installer->addFileOperation('rename', array($temp_file, $old, false));
  100. $this->installer->addFileOperation('delete', array($temp_file));
  101. }
  102. }
  103. return $test;
  104. }
  105. }
  106. ?>