Commit 3718f6e6 authored by Chris Graham's avatar Chris Graham
Browse files

Fixed MANTIS-3789

parent e24d0825
Loading
Loading
Loading
Loading
+45 −12
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ $_title->evaluate_echo();
$type = isset($_GET['type']) ? $_GET['type'] : '0';

require_code('version2');
require_code('files2');

global $REMOTE_BASE_URL;
$REMOTE_BASE_URL = get_brand_base_url();
@@ -144,6 +145,7 @@ if (cms_srv('REQUEST_METHOD') == 'POST') {
        if ($submit_to == 'live') {
            $git_commit_id = do_git_commit($git_commit_message, $fixed_files, $git_commit_command_data);
            if ($git_commit_id !== null) {
                echo '<!-- ' . $git_commit_command_data . ' -->';
                $git_url = COMPOSR_REPOS_URL . '/commit/' . $git_commit_id;
                $done['Committed to git'] = $git_url;
            } else {
@@ -159,11 +161,17 @@ if (cms_srv('REQUEST_METHOD') == 'POST') {
    }

    // Make tracker comment with fix link
    $create_hotfix = (post_param_integer('create_hotfix', 0) == 1);
    $tracker_comment_message = '';
    if ($git_commit_id !== null) {
        $tracker_comment_message .= 'Fixed in git commit ' . escape_html($git_commit_id) . ' (' . escape_html($git_url) . ' - link will become active once code pushed to GitLab)' . "\n\n";
        $tracker_comment_message .= 'Fixed in git commit ' . escape_html($git_commit_id) . ' (' . escape_html($git_url) . ' - link will become active once code pushed to GitLab)';
        if ($create_hotfix) {
            $tracker_comment_message .= "\n\n";
        }
    }
    if ($create_hotfix) {
        $tracker_comment_message .= 'A hotfix (a TAR of files to upload) have been uploaded to this issue. These files are made to the latest intra-version state (i.e. may roll in earlier fixes too if made to the same files) - so only upload files newer than what you have already. Always take backups of files you are replacing or keep a copy of the manual installer for your version, and only apply fixes you need. These hotfixes are not necessarily reliable or well supported. Not sure how to extract TAR files to your Windows computer? Try 7-zip (http://www.7-zip.org/).';
    }
    $update_post_id = create_tracker_post($tracker_id, $tracker_comment_message);
    if ($update_post_id !== null) {
        $done['Created update post on tracker'] = null;
@@ -171,19 +179,24 @@ if (cms_srv('REQUEST_METHOD') == 'POST') {
        $done['Failed to create update post on tracker'] = null;
    }
    // A TAR of fixed files is uploaded to the tracker issue (correct relative file paths intact)
    if ($create_hotfix) {
        $file_id = upload_to_tracker_issue($tracker_id, create_hotfix_tar($tracker_id, $fixed_files));
        if ($file_id !== null) {
            $done['Uploaded hotfix'] = null;
        } else {
            $done['Failed to upload hotfix'] = null;
        }
    }
    // The tracker issue gets closed
    $close_issue = (post_param_integer('close_issue', 0) == 1);
    if ($close_issue) {
        $close_success = close_tracker_issue($tracker_id);
        if ($close_success) {
            $done['Closed tracker issue'] = null;
        } else {
            $done['Failed to close tracker issue'] = null;
        }
    }

    // If a forum post ID was given, an automatic reply is given pointing to the tracker issue
    $post_id = post_param_integer('post_id', null);
@@ -209,7 +222,7 @@ if (cms_srv('REQUEST_METHOD') == 'POST') {

    if (count($addons_involved) != 0) {
        $addons_involved = array_unique($addons_involved);
        echo '<p><strong>This was for a non-bundled addon.</strong> Remember to run <a href="' . escape_html(get_base_url()) . '/adminzone/index.php?page=build_addons&amp;addon_limit=' . escape_html(urlencode(implode(',', $addons_involved))) . '">the addon update script</a>, and then upload the appropriate addon TARs and post the has-updated comments.</p>';
        echo '<p><strong>This was for a non-bundled addon.</strong> Remember to run <a href="' . escape_html(get_base_url()) . '/adminzone/index.php?page=build_addons&amp;addon_limit=' . escape_html(urlencode(implode(',', $addons_involved))) . '">the addon update script</a>, and then upload the appropriate addon TARs and post the has-updated comments (or when the next patch release if this is what is currently preferred).</p>';
    }

    return;
@@ -222,10 +235,12 @@ require_code('version2');
$on_disk_version = get_version_dotted();

$git_found = git_find_uncommitted_files();
if (@$_GET['full_scan'] == '1') {
$do_full_scan = (get_param_integer('full_scan', 0) == 1);
if (($do_full_scan) || (count($git_found) == 0)) {
    $files = push_bugfix_do_dir($git_found, 24 * 60 * 60);
    if (count($files) == 0) {
        $files = push_bugfix_do_dir($git_found, 24 * 60 * 60 * 14);
        $days = min(14, round(time() - filemtime(get_file_base() . '/index.php')) / (60 * 60 * 24) - 1);
        $files = push_bugfix_do_dir($git_found, 24 * 60 * 60 * $days);
    }
} else {
    $files = array_keys($git_found);
@@ -236,12 +251,8 @@ $git_status_2 = ' <span style="font-size: 0.8em">(if not entered a new one will
$git_status_3 = 'Git commit ID';
$choose_files_label = 'Choose files';

if ((count($files) == 0) && (@$_GET['full_scan'] != '1')) {
if ((count($git_found) == 0) && (!$do_full_scan)) {
    echo '<p><em>Found no changed files so done a full filesystem scan (rather than relying on git). You can enter a git ID or select files.</p>';
    $files = push_bugfix_do_dir($git_found, 24 * 60 * 60);
    if (count($files) == 0) {
        $files = push_bugfix_do_dir($git_found, 24 * 60 * 60 * 14);
    }
    $git_status_3 = 'Git commit ID';
    $choose_files_label = 'Choose files';
}
@@ -454,6 +465,18 @@ echo <<<END
        <div>
            <label for="tracker_id">Tracker ID to attach to <span style="font-size: 0.8em">(if not entered a new one will be made)</span></label>
            <input name="tracker_id" id="tracker_id" size="5" type="number" value="" placeholder="optional" />

            <div style="float: right">
                <div style="display: inline-block">
                    <input name="close_issue" id="close_issue" type="checkbox" value="1" checked="checked" />
                    <label for="close_issue">Close issue?</label>
                </div>

                <div style="display: inline-block">
                    <input name="create_hotfix" id="create_hotfix" type="checkbox" value="1" checked="checked" />
                    <label for="create_hotfix">Create hotfix?</label>
                </div>
            </div>
        </div>

        <div>
@@ -547,12 +570,22 @@ function do_git_commit($git_commit_message, $files, &$git_commit_command_data)

    chdir(get_file_base());

    $git_commit_command_data = '';

    // Add
    $cmd = $GIT_PATH . ' add';
    foreach ($files as $file) {
        $cmd .= ' ' . escapeshellarg($file);
    }
    $git_commit_command_data .= shell_exec($cmd . ' 2>&1');

    // Commit
    $cmd = $GIT_PATH . ' commit';
    foreach ($files as $file) {
        $cmd .= ' ' . escapeshellarg($file);
    }
    $cmd .= ' -m ' . escapeshellarg($git_commit_message);
    $git_commit_command_data = shell_exec($cmd . ' 2>&1');
    $git_commit_command_data .= shell_exec($cmd . ' 2>&1');

    $matches = array();
    if (preg_match('# ([\da-z]+)\]#', $git_commit_command_data, $matches) != 0) {
@@ -631,7 +664,6 @@ function create_forum_post($replying_to_post, $post_reply_title, $post_reply_mes
function create_hotfix_tar($tracker_id, $files)
{
    require_code('make_release');
    require_code('files2');
    require_code('tar');

    $builds_path = get_builds_path();
@@ -709,7 +741,7 @@ function push_bugfix_do_dir($git_found, $seconds_since, $subdir = '')
    $dh = opendir($stub);
    if ($dh) {
        while (($file = readdir($dh)) !== false) {
            if (($file != 'push_bugfix.php') && (!should_ignore_file($stub . $file, IGNORE_CUSTOM_DIR_SUPPLIED_CONTENTS | IGNORE_CUSTOM_DIR_GROWN_CONTENTS | IGNORE_HIDDEN_FILES | IGNORE_NONBUNDLED_SCATTERED | IGNORE_USER_CUSTOMISE | IGNORE_BUNDLED_VOLATILE | IGNORE_BUNDLED_UNSHIPPED_VOLATILE))) {
            if (!should_ignore_file((($subdir == '') ? '' : ($subdir . '/')) . $file, IGNORE_CUSTOM_DIR_GROWN_CONTENTS | IGNORE_HIDDEN_FILES | IGNORE_USER_CUSTOMISE | IGNORE_BUNDLED_VOLATILE | IGNORE_BUNDLED_UNSHIPPED_VOLATILE)) {
                $full_path = $stub . $file;
                $path = (($subdir == '') ? '' : ($subdir . '/')) . $file;

@@ -724,5 +756,6 @@ function push_bugfix_do_dir($git_found, $seconds_since, $subdir = '')
            }
        }
    }
    sort($out);
    return $out;
}