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); }