Example #1
0
 function rm_dir($dir)
 {
     $files = array_diff(scandir($dir), array('.', '..'));
     foreach ($files as $file) {
         is_dir($dir . '/' . $file) ? rm_dir($dir . '/' . $file) : unlink($dir . '/' . $file);
     }
     return rmdir($dir);
 }
Example #2
0
/**
 * A version of rm_dir which does not exits on error.
 *
 * @param  string $filename directory or file to remove
 * @param  bool $filesOnly either to remove the containing directory as well or not
 */
function rm_dir($filename, $filesOnly = false)
{
    if (is_file($filename)) {
        @unlink($filename) or CLI::logging(CLI::error("Could not remove file {$filename}") . "\n");
    } else {
        foreach (glob("{$filename}/*") as $f) {
            rm_dir($f);
        }
        if (!$filesOnly) {
            @rmdir($filename) or CLI::logging(CLI::error("Could not remove directory {$filename}") . "\n");
        }
    }
}
Example #3
0
 public function deleteModule($id)
 {
     $info = $this->getInfoById($id);
     if (empty($info)) {
         show_error('模块不存在', true);
     }
     $info = $info[0];
     // 删除src目录中所有源码
     $modulePath = C('SRC_PATH') . '/' . $info->storename;
     rm_dir($modulePath);
     // 删除模板环境中src软链
     $siteSrcPath = C('PROJECT.SITE_PATH') . '/' . C('PROJECT.TEMP_DIR') . '/' . C('PROJECT.SRC_DIR');
     @unlink($siteSrcPath . '/' . $info->filename);
     // 从数据库删除
     $this->find($id)->delete();
     return true;
 }
Example #4
0
/**
 * [rm_dir 删除级联目录]
 * @param  [string] $path [description]
 * @return [type]       [description]
 */
function rm_dir($path)
{
    if (!is_dir($path)) {
        echo '目录不存在';
        return false;
    }
    $dh = opendir($path);
    while (($row = readdir($dh)) !== false) {
        if ($row === '.' || $row === '..') {
            continue;
        }
        //判断是否是目录不是直接删
        if (!is_dir($path . '/' . $row)) {
            unlink($path . '/' . $row);
        } else {
            rm_dir($path . '/' . $row);
            echo $path . '/' . $row, '<br />';
        }
    }
    //先关闭目录
    closedir($dh);
    rmdir($path);
    return true;
}
Example #5
0
function rm_dir($dir)
{
    if (is_file(substr($dir, 0, -1))) {
        @unlink(substr($dir, 0, -1));
        return;
    }
    if ($d = opendir($dir)) {
        while (($f = readdir($d)) !== false) {
            if ($f != '.' && $f != '..') {
                rm_dir($dir . $f . DIRECTORY_SEPARATOR);
            }
        }
        @rmdir($dir . $f);
    }
}
Example #6
0
        if (is_dir($f)) {
            exec($com . " -r -f " . escapeshellarg($f) . " 2>&1", $out);
            if (!empty($out)) {
                echo "{$strRmDirFailed} " . hc($f) . "<br>" . hs($out[0]) . "...";
                exit;
            }
        } else {
            exec($com . " -f " . escapeshellarg($f) . " 2>&1", $out);
            if (!empty($out)) {
                echo "{$strDeleteFileError} " . hc($f) . "<br>" . hs($out[0]) . "...";
                exit;
            }
        }
    }
    echo "success";
    exit;
}
foreach ($files as $f) {
    if (is_dir($f)) {
        rm_dir($f);
        if (is_dir($f)) {
            echo "{$strRmDirFailed} " . hc($f) . "...";
            exit;
        }
    } elseif (!@unlink($f)) {
        echo "{$strDeleteFileError} " . hc($f) . "...";
        exit;
    }
}
echo "success";
exit;
Example #7
0
 /**
  * deletes a user entirely from the database along with local files
  *
  * @param string @email user's email
  * @param string @pw user's password
  *
  * @return boolean
  */
 public function deleteUser($token, $uid, $pw)
 {
     global $connection;
     $con = $connection;
     $pw = trim($pw);
     // check for empty values
     if (empty($pw)) {
         $this->errors[] = "Please enter your correct password";
         return false;
     }
     // check token validation
     if (!Token::validateToken($token)) {
         $this->error = true;
         $this->errors[] = "Token is not valid.";
         return false;
     }
     $user = Auth::getUserDetails($uid);
     // if password is wrong
     if (!is_object($user)) {
         $this->errors[] = "Details are not correct.";
         return false;
     }
     // if the given password doesn't match the user password in the db
     if (!password_verify($pw, $user->password)) {
         $this->errors[] = "Details are not correct.";
         return false;
     }
     // root path to the user's local server folder
     $path = DEF_IMG_UP_DIR . $user->id . DS;
     // all good, begin deleting all user data
     // useing transactions
     // store the queries to be executed
     $queries = [];
     // delete from login_info
     $sql1 = "DELETE FROM " . TABLE_INFO . " WHERE id = {$user->id} LIMIT 1";
     $queries[] = $con->prepare($sql1);
     // delete from users
     $sql2 = "DELETE FROM " . TABLE_USERS . " WHERE id = {$user->id} LIMIT 1";
     $queries[] = $con->prepare($sql2);
     // delete from user_privacy
     $sql3 = "DELETE FROM " . TABLE_PRIVACY . " WHERE user_id = {$user->id} LIMIT 1";
     $queries[] = $con->prepare($sql3);
     // being transaction and stop auto commit
     $con->beginTransaction();
     // execute all the queries
     $count = count($queries);
     $affected_rows = 0;
     for ($i = 0; $i < $count; $i++) {
         $queries[$i]->execute();
         if ($queries[$i]->rowCount() == 1) {
             $affected_rows++;
         } else {
             $this->errors[$i + 1] = $queries[$i]->queryString;
         }
     }
     // if the deleted rows count is not the same as the queries count, roll back everything
     if ($affected_rows !== $count) {
         $con->rollBack();
         return false;
     } elseif (!rm_dir($path)) {
         $this->errors['folder'] = "Error deleting local folder.";
         return $errors;
     } else {
         // delete from remaining tables
         // delete pictures
         $sql = "DELETE FROM " . TABLE_PROFILE_PICS . " WHERE user_id = {$user->id} LIMIT 1";
         $con->exec($sql);
         // delete questions
         $sql = "DELETE FROM " . TABLE_QUESTIONS . " WHERE uid = {$user->id} LIMIT 1";
         $con->exec($sql);
         // delete comments
         $sql = "DELETE FROM " . TABLE_COMMENTS . " WHERE uid = {$user->id} LIMIT 1";
         $con->exec($sql);
         // delete points
         $sql = "DELETE FROM " . TABLE_POINTS . " WHERE user_id = {$user->id} LIMIT 1";
         $con->exec($sql);
         // delete reports
         $sql = "DELETE FROM " . TABLE_REPORTS . " WHERE reporter = {$user->id} LIMIT 1";
         $con->exec($sql);
         // delete messages
         $sql = "DELETE FROM " . TABLE_MESSAGES . " WHERE user_id OR sender_id = {$user->id} LIMIT 1";
         $con->exec($sql);
         // confirm the actions
         $con->commit();
         return true;
     }
 }
Example #8
0
function rm_dir($dir)
{
    $cont = glob($dir . '/*');
    foreach ($cont as $file) {
        if (is_dir($file) && !is_link($file)) {
            rm_dir($file);
        } else {
            @unlink($file);
        }
    }
    @rmdir($dir);
}
Example #9
0
 /**
  * 删除cache文件夹
  */
 public function end()
 {
     rm_dir(self::$cacheDir);
 }
 /**
  * 清除掉冗余的配置文件
  * @param $types
  */
 private function cleanupDir($types)
 {
     // 获取已存在的小图配置文件夹列表
     $imergePath = $this->root . '/' . C('IMERGE_IMAGE_DIR');
     $entries = scandir($imergePath);
     foreach ($entries as $entry) {
         $typePath = $imergePath . '/' . $entry;
         // 如果这个文件夹名,在$types中不存在,则表示这张大图已经废弃
         if ($entry[0] !== '.' && is_dir($typePath) && !in_array($entry, $types)) {
             rm_dir($typePath);
             // 同时还要删除相应的大图,及大图配置
             $cOutFiles = glob($this->root . '/' . C('IMERGE_SPRITE_DIR') . '/' . $entry . '.*');
             //                var_dump($this->root.C('COUT_DIR').'/'.$entry.'_*');
             if ($cOutFiles) {
                 foreach ($cOutFiles as $file) {
                     unlink($file);
                 }
             }
         }
     }
 }
Example #11
0
/**
 * 删除目录
 * @param  string $dir 目录
 * @return boolean
 */
function rm_dir($dir)
{
    if (is_dir($dir) && !@rmdir($dir)) {
        foreach (scandir($dir) as $key => $val) {
            if ($val !== '.' && $val !== '..' && is_dir("{$dir}/{$val}")) {
                rm_dir("{$dir}/{$val}");
            } elseif ($val !== '.' && $val !== '..' && is_file("{$dir}/{$val}")) {
                unlink("{$dir}/{$val}");
            }
        }
        return rmdir($dir);
    }
    return true;
}
Example #12
0
 /**
  * 删除一个文件(夹),同时删除svn
  * @param $path
  */
 public static final function rmLocalAndSvn($path)
 {
     if (is_dir($path)) {
         rm_dir($path);
     } else {
         @unlink($path);
     }
     shell_exec_ensure(C('SVN') . ' del ' . $path . ' --force', false, false);
 }
Example #13
0
function run_upgrade($command, $args)
{
    CLI::logging("UPGRADE", PROCESSMAKER_PATH . "upgrade.log");
    CLI::logging("Checking files integrity...\n");
    //setting flag to true to check into sysGeneric.php
    $flag = G::isPMUnderUpdating(1);
    //start to upgrade
    $checksum = System::verifyChecksum();
    if ($checksum === false) {
        CLI::logging(CLI::error("checksum.txt not found, integrity check is not possible") . "\n");
        if (!CLI::question("Integrity check failed, do you want to continue the upgrade?")) {
            CLI::logging("Upgrade failed\n");
            die;
        }
    } else {
        if (!empty($checksum['missing'])) {
            CLI::logging(CLI::error("The following files were not found in the installation:") . "\n");
            foreach ($checksum['missing'] as $missing) {
                CLI::logging(" {$missing}\n");
            }
        }
        if (!empty($checksum['diff'])) {
            CLI::logging(CLI::error("The following files have modifications:") . "\n");
            foreach ($checksum['diff'] as $diff) {
                CLI::logging(" {$diff}\n");
            }
        }
        if (!(empty($checksum['missing']) || empty($checksum['diff']))) {
            if (!CLI::question("Integrity check failed, do you want to continue the upgrade?")) {
                CLI::logging("Upgrade failed\n");
                die;
            }
        }
    }
    CLI::logging("Clearing cache...\n");
    if (defined('PATH_C')) {
        rm_dir(PATH_C, true);
    }
    $workspaces = get_workspaces_from_args($command);
    $count = count($workspaces);
    $first = true;
    $errors = false;
    $buildCacheView = array_key_exists("buildACV", $args);
    foreach ($workspaces as $index => $workspace) {
        try {
            CLI::logging("Upgrading workspaces ({$index}/{$count}): " . CLI::info($workspace->name) . "\n");
            $workspace->upgrade($first, $buildCacheView, $workspace->name);
            $workspace->close();
            $first = false;
        } catch (Exception $e) {
            CLI::logging("Errors upgrading workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n");
            $errors = true;
        }
    }
    if ($errors) {
        CLI::logging("Upgrade finished but there were errors upgrading workspaces.\n");
        CLI::logging(CLI::error("Please check the log above to correct any issues.") . "\n");
    } else {
        CLI::logging("Upgrade successful\n");
    }
    //setting flag to false
    $flag = G::isPMUnderUpdating(0);
}
Example #14
0
 /**
  * 清除上次编译结果
  */
 private function rmOldBuildFile()
 {
     $ret = new stdClass();
     $ret->return = true;
     trigger('rm_old_build_file', $ret);
     if ($ret->return) {
         $buildPath = C('SRC.BUILD_PATH');
         $cachePath = C('SRC.BUILD_CACHE_PATH');
         rm_dir($buildPath);
         rm_dir($cachePath);
     }
 }
Example #15
0
 function rm_dir($path)
 {
     $out = '';
     if (is_dir($path)) {
         $path = substr($path, -1) == '/' ? $path : $path . '/';
         $dh = @opendir($path);
         if (!$dh) {
             return $out .= $path . ':open failed';
         }
         while (($item = readdir($dh)) !== false) {
             $item = $path . $item;
             if (basename($item) == ".." || basename($item) == ".") {
                 continue;
             }
             rm_dir($item);
         }
         closedir($dh);
         if (@rmdir($path)) {
             $out .= $path . ':okay\\n';
         } else {
             $out .= $path . ':failed\\n';
         }
     } else {
         if (@unlink($path)) {
             $out .= $path . ':okay\\n';
         } else {
             $out .= $path . ':failed\\n';
         }
     }
     return $out;
 }
 /**
  * 清除所有本地文件修改
  * 将以svn文件为准
  */
 private static function cleanLocalChange()
 {
     $cmd = 'cd ' . C('SRC.SRC_PATH') . ' && ' . C('SVN') . ' st';
     $ret = shell_exec_ensure($cmd, false);
     if (!$ret['status']) {
         $list = $ret['output'];
         $list = explode("\n", $list);
         if (!empty($list)) {
             foreach ($list as $item) {
                 // 前8位字符,表示状态信息,去掉
                 $item = trim(substr($item, 8));
                 if (!$item || $item && $item[0] === '.') {
                     continue;
                 }
                 //                    mark('忽略本地文件修改:'.$item, 'emphasize');
                 $item = C('SRC.SRC_PATH') . '/' . $item;
                 if (is_dir($item)) {
                     rm_dir($item);
                 } else {
                     @unlink($item);
                 }
             }
         }
     }
 }