ob_start(); } $github = json_decode(stripslashes($_POST['payload']), true); $ref = explode('/', $github['ref']); $user = $github['repository']['owner']['name']; $repository = $github['repository']['name']; $branch = $ref[2]; $codebase_path = $GLOBALS['codebases_path']; $codebase = sprintf('%s/%s/%s', $user, $repository, $branch); $branch_path = $codebase_path . $codebase; $commands = array("cd {$branch_path}"); // create folder structure if needed. // if no folder, we do a clone, otherwise pull if (!is_dir($branch_path)) { mkdir($branch_path, 0777, true); $commands[] = sprintf('%s clone -b %s git@github.com:%s/%s.git .', $git_path, $branch, $user, $repository); } else { $commands[] = "{$git_path} pull"; } // update submodules $commands[] = "{$git_path} submodule init"; $commands[] = "{$git_path} submodule update"; // execute commands safe_exec($commands, $output); print_r($commands); print_r($output); echo "\n\nPOST[payload]\n\n"; echo json_beautify($_POST['payload']); if ($_GET['debug_email']) { mail($_GET['debug_email'], 'git hook ' . time(), ob_get_contents()); }
/** * Returns this api response in json format * @return string $flag matching to the key in $flags */ public function json() { $output = $this->getOutput(); return json_beautify(json_encode($output)); }
<?php if (!$_POST['sql'] || !$_POST['db_name']) { exit_json(array('error' => "Missing required POST values 'sql' and/or 'db_name'.")); } $needle = '/pages/'; $end = strrpos(__FILE__, $needle); $prefix = substr(__FILE__, 0, $end); $jar_path = $prefix . '/lib/db/apgdiff-2.3.jar'; \Cms\Apgdiff::$jar_path = $jar_path; $sql = \Cms\Apgdiff::getDump(); $db_name = \Cms\Apgdiff::getDatabaseName(); $pull = \Cms\Apgdiff::getUpgradeScript($_POST['sql'], $sql); $pull_filtered = \Cms\Apgdiff::stripDrops($pull); $push = \Cms\Apgdiff::getUpgradeScript($sql, $_POST['sql']); $push_filtered = \Cms\Apgdiff::stripDrops($push); $data = array('local_database' => $_POST['db_name'], 'remote_database' => $db_name, 'tabs' => array(array('tab' => 'Pull', 'tab_caps' => 'PULL', 'left_arrow' => true, 'left_sql' => $pull_filtered, 'right_sql' => $pull), array('tab' => 'Push', 'tab_caps' => 'PUSH', 'right_arrow' => true, 'left_sql' => $push_filtered, 'right_sql' => $push), array('tab' => 'Dump', 'tab_caps' => 'DUMP', 'dump' => true, 'left_sql' => $_POST['sql'], 'right_sql' => $sql))); json_headers(); exit(json_beautify(json_encode($data)));