Пример #1
0
 public function project_page($ctl)
 {
     if (empty($_REQUEST['p'])) {
         $ctl->redirect('list.php');
     }
     $projects = $ctl->stage->get_projects_from_param($_REQUEST['p']);
     $projects_lookup = array_flip((array) $_REQUEST['p']);
     ###  Read Command output
     $previous_command = $this->read_previous_command($ctl);
     ###  Load for each project
     $locally_modified = false;
     $project_data = array();
     foreach ($projects as $project) {
         ###  Load and parse the file list
         $file_tags = $project->get_file_tags();
         $files = $project->get_affected_files();
         $project_data[$project->project_name]['project'] = $project;
         $project_data[$project->project_name]['file_lines'] = array();
         foreach ($files as $file) {
             $file_line = array('file' => $file);
             ###  Get Current Version
             $file_line['cur_vers'] = delayed_load_span(array($file), create_function('$file', now_doc('DELAY')));
             ###  Get PROD_SAFE Version
             $file_line['prod_safe_vers'] = delayed_load_span(array($file), create_function('$file', now_doc('DELAY')));
             ###  Get PROD_TEST Version
             $file_line['prod_test_vers'] = delayed_load_span(array($file), create_function('$file', now_doc('DELAY')));
             ###  Get HEAD Version
             $file_line['head_vers'] = delayed_load_span(array($file, $project, $file_tags), create_function('$file,$project,$file_tags', now_doc('DELAY')));
             ###  Do Target
             $file_line['target_vers'] = delayed_load_span(array($file, $project), create_function('$file,$project', now_doc('DELAY')));
             ###  Changes by
             $file_line['changes_by'] = delayed_load_span(array($file, $project), create_function('$file,$project', now_doc('DELAY')));
             ###  Actions
             $file_line['actions'] = delayed_load_span(array($file, $project), create_function('$file,$project', now_doc('DELAY')));
             ###  Other Projects Sharing files
             $other_projects = array();
             foreach ($ctl->stage->get_projects() as $pname) {
                 if (empty($pname) || $pname == $project->project_name) {
                     continue;
                 }
                 $other_project = new Ansible__Project($pname, $ctl->stage, false);
                 if (!in_array($other_project->get_group(), array('00_none', '01_staging', '03_testing_done', '04_prod_rollout_prep'))) {
                     continue;
                 }
                 foreach ($files as $our_file) {
                     foreach ($other_project->get_affected_files() as $their_file) {
                         if ($our_file == $their_file) {
                             if (!isset($other_projects[$pname])) {
                                 $other_projects[$pname] = array('data' => array('project' => $other_project, 'included' => isset($projects_lookup[$other_project->project_name]), 'remove_project_url' => $ctl->stage->get_projects_url($projects, $other_project->project_name)));
                             }
                             $other_projects[$pname][] = $their_file;
                         }
                     }
                 }
             }
             $project_data[$project->project_name]['other_projects'] = $other_projects;
             $project_data[$project->project_name]['remove_project_url'] = $ctl->stage->get_projects_url($projects, $project->project_name);
             $project_data[$project->project_name]['files'][] = $file_line;
         }
     }
     ///  Find all rollback points that include ALL of these projects
     require_once dirname(__FILE__) . '/../model/RollPoint.class.php';
     $proj_join = array();
     foreach ($projects as $p) {
         $proj_join[$p->project_name] = $ctl->stage->dbh()->quote($p->project_name);
     }
     $roll_points = Ansible__RollPoint::get_where(array("(SELECT COUNT(*) FROM rlpt_project r WHERE roll_point.rlpt_id = r.rlpt_id AND r.project IN (" . join(',', $proj_join) . " )) == " . count($proj_join), "(SELECT COUNT(*) FROM rlpt_project r WHERE roll_point.rlpt_id = r.rlpt_id                                               ) == " . count($proj_join)), false, 'creation_date DESC');
     return array('project_data' => $project_data, 'previous_command' => $previous_command, 'locally_modified' => $locally_modified, 'project_url_params' => $ctl->stage->get_projects_url($projects), 'roll_points' => $roll_points);
 }
Пример #2
0
 public function tagAction($projects, $tag, $user)
 {
     $point = null;
     if (in_array($tag, array('prod_rollback', 'rollout'))) {
         require_once dirname(__FILE__) . '/../model/RollPoint.class.php';
         ///  Create new RollPoint
         $point = new Ansible__RollPoint();
         $point->create(array('point_type' => $tag, 'created_by' => $user));
         ###  Look and update tags
         $seen_files = array();
         foreach ($projects as $project) {
             $point->add_project($project->project_name);
             foreach ($project->get_affected_files() as $file) {
                 ###  Make sure this file exists
                 if (file_exists($this->stage->env()->repo_base . "/{$file}") && !is_dir($this->stage->env()->repo_base . "/{$file}")) {
                     list($cur_rev) = $this->get_current_rev($file);
                     ///  Roll Point System (New Regime)
                     if (!isset($seen_files[$file])) {
                         $point->add_file($file, $cur_rev);
                     }
                     $seen_files[$file] = true;
                 } else {
                     if (!is_dir($this->stage->env()->repo_base . "/{$file}")) {
                         ///  Roll Point System (New Regime)
                         if (!isset($seen_files[$file])) {
                             $point->add_file($file, null);
                         }
                         $seen_files[$file] = true;
                     }
                 }
             }
         }
     } else {
         ###  Look and update tags
         foreach ($projects as $project) {
             foreach ($project->get_affected_files() as $file) {
                 ###  Make sure this file exists
                 if (file_exists($this->stage->env()->repo_base . "/{$file}")) {
                     list($cur_rev) = $this->get_current_rev($file);
                     /// Old Tag System (Keep around and maintain, until we are always doing live status)
                     ###  See what the tag was before...
                     $sth = dbh_query_bind("SELECT revision FROM file_tag WHERE file = ? AND tag = ?", $file, $tag);
                     $old_rev = $sth->fetch(PDO::FETCH_NUM);
                     $sth->closeCursor();
                     ###  Update the Tag DB for this file...
                     $rv = dbh_do_bind("DELETE FROM file_tag WHERE file = ? AND tag = ?", $file, $tag);
                     $rv = dbh_do_bind("INSERT INTO file_tag ( file,tag,revision ) VALUES (?,?,?)", $file, $tag, $cur_rev);
                     ###  Add to Command output whether we really changed the tag or not
                     if (!empty($old_rev) && $old_rev[0] != $cur_rev) {
                         $command_output .= "Moved {$tag} on {$file} from " . $old_rev[0] . " to {$cur_rev}\n";
                         $this->log_repo_action("TAG: Moved {$tag} on {$file} from " . $old_rev[0] . " to {$cur_rev}", $project, $user);
                     } else {
                         if (empty($old_rev)) {
                             $command_output .= "Set {$tag} on {$file} to " . $cur_rev . "\n";
                             $this->log_repo_action("TAG: Set {$tag} on {$file} to " . $cur_rev, $project, $user);
                         } else {
                             $command_output .= "Preserved {$tag} on {$file} at " . $old_rev[0] . "\n";
                             $this->log_repo_action("TAG: Preserved {$tag} on {$file} at " . $old_rev[0], $project, $user);
                         }
                     }
                 } else {
                     ###  See what the tag was before...
                     $sth = dbh_query_bind("SELECT revision FROM file_tag WHERE file = ? AND tag = ?", $file, $tag);
                     $old_rev = $sth->fetch(PDO::FETCH_NUM);
                     $sth->closeCursor();
                     ###  Update the Tag DB for this file...
                     $rv = dbh_do_bind("DELETE FROM file_tag WHERE file = ? AND tag = ?", $file, $tag);
                     ###  Add to Command output whether we really changed the tag or not
                     if (!empty($old_rev)) {
                         $command_output .= "Removed {$tag} on {$file}\n";
                         $this->log_repo_action("TAG: Removed {$tag} on {$file}", $project, $user);
                     }
                 }
             }
         }
     }
     $cmd = "TAG all files: {$tag}";
     if (empty($command_output)) {
         $command_output = '</xmp><i>No output</i>';
     }
     return array($cmd, $command_output, $point);
 }