Пример #1
0
/**
 * Repair problems in a Typeframe installation.
 * This command will configure BaseModel schemas and fix writeable directory
 * permissions.
 */
function fixPermissions($dir)
{
    static $ftp = null;
    static $depth = 0;
    $depth++;
    if (is_null($ftp)) {
        $ftp = new Typeframe_File();
    }
    if (!file_exists(TYPEF_DIR . '/files' . $dir)) {
        $ftp->mkdir('/files' . $dir);
    }
    if (substr(sprintf('%o', fileperms(TYPEF_DIR . '/files/' . $dir)), -4) !== '0777') {
        $ftp->chmod(0777, '/files' . $dir);
    }
    $dh = opendir(TYPEF_DIR . '/files' . $dir);
    while (($file = readdir($dh)) !== false) {
        if (substr($file, 0, 1) != '.') {
            if (is_dir(TYPEF_DIR . '/files' . $dir . '/' . $file)) {
                fixPermissions($dir . '/' . $file);
            } else {
                $perm = substr(decoct(fileperms(TYPEF_DIR . '/files/' . $dir . '/' . $file)), 1);
                if ($perm !== '0666' && $perm !== '0777') {
                    $ftp->chmod(0666, '/files/' . $dir . '/' . $file);
                }
            }
        }
    }
    $depth--;
    if ($depth == 0) {
        $ftp->close();
        $ftp = null;
    }
}
Пример #2
0
 /**
  * Recurisvely copy files and directories via FTP.
  * @param Typeframe_Ftp $ftp
  * @param string $src The source directory.
  * @param string $dst The destination directory.
  */
 private static function _CopyFiles(Typeframe_File $ftp, $src, $dst, $package, $force)
 {
     $files = scandir($src);
     $xml = null;
     if (file_exists(TYPEF_SOURCE_DIR . '/packages/' . $package . '.xml')) {
         $xml = simplexml_load_file(TYPEF_SOURCE_DIR . '/packages/' . $package . '.xml');
     }
     foreach ($files as $file) {
         if (substr($file, 0, 1) == '.') {
             continue;
         }
         if (is_file("{$src}/{$file}")) {
             // Copy the file depending on $force rules
             $copy = false;
             if (!file_exists(TYPEF_DIR . "{$dst}/{$file}")) {
                 $copy = true;
             } else {
                 if ($force === true) {
                     $copy = true;
                 } else {
                     // Check for filename in $force
                     if (is_array($force) && in_array(substr("{$dst}/{$file}", 1), $force)) {
                         $copy = true;
                     } else {
                         if ($xml) {
                             foreach ($xml->file as $xfile) {
                                 $fn = trim("{$xfile}");
                                 if (substr($fn, 0, 1) == '/') {
                                     $fn = substr($fn, 1);
                                 }
                                 $fn = preg_replace('/\\/+/', '/', $fn);
                                 $dn = "{$dst}/{$file}";
                                 if (substr($dn, 0, 1) == '/') {
                                     $dn = substr($dn, 1);
                                 }
                                 $dn = preg_replace('/\\/+/', '/', $dn);
                                 if ($fn == $dn) {
                                     $md5 = md5_file(TYPEF_DIR . '/' . $fn);
                                     if ($xfile['md5'] == $md5) {
                                         $copy = true;
                                     }
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
             if ($copy) {
                 $ftp->copy("{$src}/{$file}", "{$dst}/{$file}");
             }
         } else {
             if (is_dir("{$src}/{$file}")) {
                 // TODO: Make the directory if it does not exist
                 if (!file_exists(TYPEF_DIR . "/{$dst}/{$file}")) {
                     $ftp->mkdir("{$dst}/{$file}");
                 }
                 self::_CopyFiles($ftp, "{$src}/{$file}", "{$dst}/{$file}", $package, $force);
                 // TODO: What if the file exists and is not a directory?
             }
         }
         // TODO: Is there another possibility?
     }
 }