Code Coverage for /home/user/workspace/all/Pyrus/src/Pyrus/FileTransactions/Rename.php

Coverage: 35%

Aggregate Code Coverage for all tests

       1           : <?php
       2           : /**
       3           :  * PEAR2_Pyrus_FileTransactions_Rename
       4           :  *
       5           :  * PHP version 5
       6           :  *
       7           :  * @category  PEAR2
       8           :  * @package   PEAR2_Pyrus
       9           :  * @author    Greg Beaver <cellog@php.net>
      10           :  * @copyright 2008 The PEAR Group
      11           :  * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
      12           :  * @version   SVN: $Id$
      13           :  * @link      http://svn.pear.php.net/wsvn/PEARSVN/Pyrus/
      14           :  */
      15           : 
      16           : /**
      17           :  * Handle files which are renamed on installation. This alters the standard file
      18           :  * transaction to rename an installed file to a different filename.
      19           :  *
      20           :  * @category  PEAR2
      21           :  * @package   PEAR2_Pyrus
      22           :  * @author    Greg Beaver <cellog@php.net>
      23           :  * @copyright 2008 The PEAR Group
      24           :  * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
      25           :  * @link      http://svn.pear.php.net/wsvn/PEARSVN/Pyrus/
      26           :  */
      27         1 : class PEAR2_Pyrus_FileTransactions_Rename implements PEAR2_Pyrus_IFileTransaction
      28           : {
      29           :     public function check($data, &$errors)
      30           :     {
      31         1 :         if (!file_exists($data[0])) {
      32           :             $errors[] = "cannot rename file $data[0], doesn't exist";
      33           :         }
      34           : 
      35           :         // check that dest dir. is writable
      36         1 :         if (!is_writable(dirname($data[1]))) {
      37           :             $errors[] = "permission denied ($type): $data[1]";
      38           :         }
      39         1 :     }
      40           : 
      41           :     public function commit($data, &$errors)
      42           :     {
      43         1 :         $test = file_exists($data[1]) ? @unlink($data[1]) : null;
      44         1 :         if (!$test && file_exists($data[1])) {
      45           :             $extra = '';
      46           :             if ($data[2]) {
      47           :                 $extra = ', this extension must be installed manually.  Rename to "' .
      48           :                     basename($data[1]) . '"';
      49           :             }
      50           : 
      51           :             if (!isset($this->_options['soft'])) {
      52           :                 PEAR2_Pyrus_Log::log(1, 'Could not delete ' . $data[1] . ', cannot rename ' .
      53           :                     $data[0] . $extra);
      54           :             }
      55           : 
      56           :             if (!isset($this->_options['ignore-errors'])) {
      57           :                 return false;
      58           :             }
      59           :         }
      60           : 
      61           :         // permissions issues with rename - copy() is far superior
      62         1 :         $perms = @fileperms($data[0]);
      63         1 :         if (!@copy($data[0], $data[1])) {
      64           :             PEAR2_Pyrus_Log::log(1, 'Could not rename ' . $data[0] . ' to ' . $data[1] .
      65           :                 ' ' . $php_errormsg);
      66           :             return false;
      67           :         }
      68           : 
      69           :         // copy over permissions, otherwise they are lost
      70         1 :         @chmod($data[1], $perms);
      71         1 :         @unlink($data[0]);
      72         1 :         PEAR2_Pyrus_Log::log(3, "+ mv $data[0] $data[1]");
      73         1 :     }
      74           : 
      75           :     public function rollback($data, &$errors)
      76           :     {
      77           :         @unlink($data[0]);
      78           :         PEAR2_Pyrus_Log::log(3, "+ rm $data[0]");
      79           :     }
      80           : 
      81           :     public function cleanup(){}
      82         1 : }