PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/php/PEAR/Installer/Role/Cfg.php

https://bitbucket.org/adarshj/convenient_website
PHP | 106 lines | 55 code | 7 blank | 44 comment | 12 complexity | faee4c4408cf77aa73c608b54ed3a587 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-2-Clause, GPL-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * PEAR_Installer_Role_Cfg
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * @category pear
  8. * @package PEAR
  9. * @author Greg Beaver <cellog@php.net>
  10. * @copyright 2007-2009 The Authors
  11. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  12. * @version CVS: $Id: Cfg.php 313023 2011-07-06 19:17:11Z dufuz $
  13. * @link http://pear.php.net/package/PEAR
  14. * @since File available since Release 1.7.0
  15. */
  16. /**
  17. * @category pear
  18. * @package PEAR
  19. * @author Greg Beaver <cellog@php.net>
  20. * @copyright 2007-2009 The Authors
  21. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  22. * @version Release: 1.9.4
  23. * @link http://pear.php.net/package/PEAR
  24. * @since Class available since Release 1.7.0
  25. */
  26. class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common
  27. {
  28. /**
  29. * @var PEAR_Installer
  30. */
  31. var $installer;
  32. /**
  33. * the md5 of the original file
  34. *
  35. * @var unknown_type
  36. */
  37. var $md5 = null;
  38. /**
  39. * Do any unusual setup here
  40. * @param PEAR_Installer
  41. * @param PEAR_PackageFile_v2
  42. * @param array file attributes
  43. * @param string file name
  44. */
  45. function setup(&$installer, $pkg, $atts, $file)
  46. {
  47. $this->installer = &$installer;
  48. $reg = &$this->installer->config->getRegistry();
  49. $package = $reg->getPackage($pkg->getPackage(), $pkg->getChannel());
  50. if ($package) {
  51. $filelist = $package->getFilelist();
  52. if (isset($filelist[$file]) && isset($filelist[$file]['md5sum'])) {
  53. $this->md5 = $filelist[$file]['md5sum'];
  54. }
  55. }
  56. }
  57. function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
  58. {
  59. $test = parent::processInstallation($pkg, $atts, $file, $tmp_path, $layer);
  60. if (@file_exists($test[2]) && @file_exists($test[3])) {
  61. $md5 = md5_file($test[2]);
  62. // configuration has already been installed, check for mods
  63. if ($md5 !== $this->md5 && $md5 !== md5_file($test[3])) {
  64. // configuration has been modified, so save our version as
  65. // configfile-version
  66. $old = $test[2];
  67. $test[2] .= '.new-' . $pkg->getVersion();
  68. // backup original and re-install it
  69. PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  70. $tmpcfg = $this->config->get('temp_dir');
  71. $newloc = System::mkdir(array('-p', $tmpcfg));
  72. if (!$newloc) {
  73. // try temp_dir
  74. $newloc = System::mktemp(array('-d'));
  75. if (!$newloc || PEAR::isError($newloc)) {
  76. PEAR::popErrorHandling();
  77. return PEAR::raiseError('Could not save existing configuration file '.
  78. $old . ', unable to install. Please set temp_dir ' .
  79. 'configuration variable to a writeable location and try again');
  80. }
  81. } else {
  82. $newloc = $tmpcfg;
  83. }
  84. $temp_file = $newloc . DIRECTORY_SEPARATOR . uniqid('savefile');
  85. if (!@copy($old, $temp_file)) {
  86. PEAR::popErrorHandling();
  87. return PEAR::raiseError('Could not save existing configuration file '.
  88. $old . ', unable to install. Please set temp_dir ' .
  89. 'configuration variable to a writeable location and try again');
  90. }
  91. PEAR::popErrorHandling();
  92. $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");
  93. $this->installer->addFileOperation('rename', array($temp_file, $old, false));
  94. $this->installer->addFileOperation('delete', array($temp_file));
  95. }
  96. }
  97. return $test;
  98. }
  99. }