Ejemplo n.º 1
0
// create a new file in repo
$filename = $repo->getRepositoryPath() . $prev_file;
if (!file_exists($filename)) {
    echo json_encode(array('result' => false, 'message' => 'file is not exists.'));
    return;
}
$arr = array_map('trim', explode("/", $filename));
$is_dir = array_pop($arr) == '';
setlocale(LC_CTYPE, "ko_KR.UTF-8");
$repo->setConfig($_SESSION['username']);
$repo->setConfigExt('core.quotepath false');
if ($is_dir) {
    $arr = explode('/', $prev_file);
    $filename = explode("/", $_POST['filename']);
    $arr[count($arr) - 2] = $filename[0];
    $repo->renameFile($prev_file, join("/", $arr));
    echo json_encode(array('result' => true, 'message' => 'directory is success'));
    return;
} else {
    if (!is_support_type($filename)) {
        echo json_encode(array('result' => false, 'message' => 'file type is not supported type'));
        return;
    }
    $arr = explode('/', $prev_file);
    $filename = explode("/", $_POST['filename']);
    $arr[count($arr) - 1] = $filename[0];
    $repo->renameFile($prev_file, join("/", $arr));
    $repo->commit("add " . $filename, "-a");
    echo json_encode(array('result' => true, 'message' => 'file is success'));
    return;
}
Ejemplo n.º 2
0
<?php

error_reporting(E_ALL);
include_once '../../../../bootstrap.php';
include_once 'common.php';
use Cz\Git\GitRepository;
header('Content-Type: application/json');
$id = $_POST['id'];
if (!$id) {
    echo json_encode(array('result' => false, 'message' => 'Not found'));
    exit;
}
$m = new MongoClient();
// select a rowbase
$db = $m->store;
$components = $db->components;
$row = $components->findOne(array('_id' => new MongoId($id)));
$isMy = true;
if ($id && ($row['login_type'] != $_SESSION['login_type'] || $row['userid'] != $_SESSION['userid'])) {
    echo json_encode(array('result' => false, 'message' => 'Access denined.'));
    exit;
}
$dir = REPOSITORY . '/' . $id . '/';
$repo = new GitRepository($dir);
//var_dump($_POST);
setlocale(LC_CTYPE, "ko_KR.UTF-8");
$repo->setConfig($_SESSION['username']);
$commit_message = $_POST['commit_message'];
$ret = $repo->commit($commit_message, "-a");
die(json_encode(array('result' => $ret ? true : false)));
Ejemplo n.º 3
0
}
$total = count($_FILES['files']['tmp_name']);
setlocale(LC_CTYPE, "ko_KR.UTF-8");
$root = $repo->getRepositoryPath();
$result = array();
$file_names = array();
for ($i = 0; $i < $total; $i++) {
    $name = $_FILES['files']['name'][$i];
    $tmp_name = $_FILES['files']['tmp_name'][$i];
    $error = $_FILES['files']['error'][$i];
    $filename = $root . '/' . $name;
    $filename = file_numbering($filename);
    $is_uploaded = false;
    if ($error == UPLOAD_ERR_OK) {
        $is_uploaded = @move_uploaded_file($tmp_name, $filename);
        if ($is_uploaded) {
            $name = end(explode('/', $filename));
            // git add
            $repo->addFile($name);
            // 권한 넣기
            chmod($name, 0666);
        } else {
        }
    }
    $result[$i] = array('created_filename' => $filename, 'name' => $name, 'uploaded' => $is_uploaded, 'error' => $error);
    $file_names[] = $name;
}
// commit 하기
$commit_message = "upload files : " . implode(",", $file_names);
$repo->commit($commit_message);
die(json_encode(array('result' => $result)));
Ejemplo n.º 4
0
    $is_uploaded = true;
    $result[] = array('name' => $name, 'uploaded' => $is_uploaded, 'error' => $error);
    $commitPostfix = " - " . $url;
} else {
    // upload files
    $total = count($_FILES['files']['tmp_name']);
    for ($i = 0; $i < $total; $i++) {
        $name = $_FILES['files']['name'][$i];
        $tmp_name = $_FILES['files']['tmp_name'][$i];
        $error = $_FILES['files']['error'][$i];
        $filename = $root . '/' . $name;
        $filename = file_numbering($filename);
        $is_uploaded = false;
        if ($error == UPLOAD_ERR_OK) {
            $is_uploaded = move_uploaded_file($tmp_name, $filename);
            if ($is_uploaded) {
                $name = end(explode('/', $filename));
                // git add
                $repo->addFile($name);
                $file_list[] = $name;
                // 권한 넣기
                chmod($name, 0666);
            } else {
                var_dump(error_get_last());
            }
        }
        $result[$i] = array('name' => $name, 'uploaded' => $is_uploaded, 'error' => $error);
    }
}
$repo->commit("upload " . implode(",", $file_list) . " " . $commitPostfix, "-a");
die(json_encode(array('result' => $result)));