• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Migration/DBUpdate_904/classes/class.ilUpdateUtils.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003 +-----------------------------------------------------------------------------+
00004 | ILIAS open source                                                           |
00005 +-----------------------------------------------------------------------------+
00006 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007 |                                                                             |
00008 | This program is free software; you can redistribute it and/or               |
00009 | modify it under the terms of the GNU General Public License                 |
00010 | as published by the Free Software Foundation; either version 2              |
00011 | of the License, or (at your option) any later version.                      |
00012 |                                                                             |
00013 | This program is distributed in the hope that it will be useful,             |
00014 | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016 | GNU General Public License for more details.                                |
00017 |                                                                             |
00018 | You should have received a copy of the GNU General Public License           |
00019 | along with this program; if not, write to the Free Software                 |
00020 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021 +-----------------------------------------------------------------------------+
00022 */
00023 
00037 class ilUpdateUtils
00038 {
00039         
00040         function removeTrailingPathSeparators($path)
00041         {
00042                 $path = preg_replace("/[\/\\\]+$/", "", $path);
00043                 return $path;
00044         }
00045         
00046 
00047 
00055         function getWebspaceDir($mode = "filesystem")
00056         {
00057                 global $ilias;
00058 
00059                 if ($mode == "filesystem")
00060                 {
00061                         return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
00062                 }
00063                 else
00064                 {
00065                         if (defined("ILIAS_MODULE"))
00066                         {
00067                                 return "../".ILIAS_WEB_DIR."/".$ilias->client_id;
00068                         }
00069                         else
00070                         {
00071                                 return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
00072                         }
00073                 }
00074 
00075                 //return $ilias->ini->readVariable("server","webspace_dir");
00076         }
00077 
00081         function getDataDir()
00082         {
00083                 return CLIENT_DATA_DIR;
00084                 //global $ilias;
00085 
00086                 //return $ilias->ini->readVariable("server", "data_dir");
00087         }
00088 
00103         function makeDir($a_dir)
00104         {
00105                 $a_dir = trim($a_dir);
00106 
00107                 // remove trailing slash (bugfix for php 4.2.x)
00108                 if (substr($a_dir,-1) == "/")
00109                 {
00110                         $a_dir = substr($a_dir,0,-1);
00111                 }
00112 
00113                 // check if a_dir comes with a path
00114                 if (!($path = substr($a_dir,0, strrpos($a_dir,"/") - strlen($a_dir))))
00115                 {
00116                         $path = ".";
00117                 }
00118 
00119                 // create directory with file permissions of parent directory
00120                 umask(0000);
00121                 return @mkdir($a_dir,fileperms($path));
00122         }
00123 
00124 
00137         function makeDirParents($a_dir)
00138         {
00139                 $dirs = array($a_dir);
00140                 $a_dir = dirname($a_dir);
00141                 $last_dirname = '';
00142                 while($last_dirname != $a_dir)
00143                 {
00144                         array_unshift($dirs, $a_dir);
00145                         $last_dirname = $a_dir;
00146                         $a_dir = dirname($a_dir);
00147                 }
00148 
00149                 // find the first existing dir
00150                 $reverse_paths = array_reverse($dirs, TRUE);
00151                 $found_index = -1;
00152                 foreach ($reverse_paths as $key => $value)
00153                 {
00154                         if ($found_index == -1)
00155                         {
00156                                 if (is_dir($value))
00157                                 {
00158                                         $found_index = $key;
00159                                 }
00160                         }
00161                 }
00162 
00163                 umask(0000);
00164                 foreach ($dirs as $dirindex => $dir)
00165                 {
00166                         // starting with the longest existing path
00167                         if ($dirindex >= $found_index)
00168                         {
00169                                 if (! file_exists($dir))
00170                                 {
00171                                         if (strcmp(substr($dir,strlen($dir)-1,1),"/") == 0)
00172                                         {
00173                                                 // on some systems there is an error when there is a slash
00174                                                 // at the end of a directory in mkdir, see Mantis #2554
00175                                                 $dir = substr($dir,0,strlen($dir)-1);
00176                                         }
00177                                         
00178                                         if (! mkdir($dir, $umask))
00179                                         {
00180                                                 error_log("Can't make directory: $dir");
00181                                                 return false;
00182                                         }
00183                                 }
00184                                 elseif (! is_dir($dir))
00185                                 {
00186                                         error_log("$dir is not a directory");
00187                                         return false;
00188                                 }
00189                                 else
00190                                 {
00191                                         // get umask of the last existing parent directory
00192                                         $umask = fileperms($dir);
00193                                 }
00194                         }
00195                 }
00196                 return true;
00197         }
00198 
00206         function delDir($a_dir)
00207         {
00208                 if (!is_dir($a_dir) || is_int(strpos($a_dir, "..")))
00209                 {
00210                         return;
00211                 }
00212 
00213                 $current_dir = opendir($a_dir);
00214 
00215                 $files = array();
00216 
00217                 // this extra loop has been necessary because of a strange bug
00218                 // at least on MacOS X. A looped readdir() didn't work
00219                 // correctly with larger directories
00220                 // when an unlink happened inside the loop. Getting all files
00221                 // into the memory first solved the problem.
00222                 while($entryname = readdir($current_dir))
00223                 {
00224                         $files[] = $entryname;
00225                 }
00226 
00227                 foreach($files as $file)
00228                 {
00229                         if(is_dir($a_dir."/".$file) and ($file != "." and $file!=".."))
00230                         {
00231                                 ilUtil::delDir(${a_dir}."/".${file});
00232                         }
00233                         elseif ($file != "." and $file != "..")
00234                         {
00235                                 unlink(${a_dir}."/".${file});
00236                         }
00237                 }
00238 
00239                 closedir($current_dir);
00240                 rmdir(${a_dir});
00241         }
00242 
00243 
00247         function getDir($a_dir)
00248         {
00249                 $current_dir = opendir($a_dir);
00250 
00251                 $dirs = array();
00252                 $files = array();
00253                 while($entry = readdir($current_dir))
00254                 {
00255                         if(is_dir($a_dir."/".$entry))
00256                         {
00257                                 $dirs[$entry] = array("type" => "dir", "entry" => $entry);
00258                         }
00259                         else
00260                         {
00261                                 $size = filesize($a_dir."/".$entry);
00262                                 $files[$entry] = array("type" => "file", "entry" => $entry,
00263                                 "size" => $size);
00264                         }
00265                 }
00266                 ksort($dirs);
00267                 ksort($files);
00268 
00269                 return array_merge($dirs, $files);
00270         }
00271 
00272 
00273 
00274 
00275 } // END class.ilUtil
00276 
00277 
00278 ?>

Generated on Fri Dec 13 2013 17:57:00 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1