function finish_test() { $this->erase_progress_bar(); $red = red_string(); $blue = blue_string(); $green = green_string(); $reset = reset_string(); $test = $this->get_name(); $triple = $this->get_triple_string(true); $phrase = $this->get_appropriate_phrase(); $colour = $this->get_appropriate_colour(); $word = "{$colour}{$phrase}:{$reset}"; // a color or a reset involves 6 characters, but gets displayed as zero. // Those 6 need to be taken into account for sprintf $string = sprintf("%-27s %20s %41s\n", $test, $word, $triple); print "{$string}"; write_status("results", strip_colour($string)); }
function log_failure($test_name, $subject, $commands, $outs, $errs, $exits, $missing_dependency, $reason) { $red = red_string(); $reset = reset_string(); // we have 1 or more outputs, only 1 error, and 1 or more commands, with the same number of error codes as commands $err_string = ""; if (is_array($commands)) { if ($exits == "Not relevent") { $command_string = ""; foreach ($commands as $command) { $command_string .= "{$red}Command:{$reset} {$command}\n"; } } else { phc_assert(is_array($exits), "Expected array of return values"); phc_assert(count($exits) == count($errs), "Expected same number of exits as exit codes"); $command_string = ""; $err_string = ""; foreach ($exits as $i => $exit) { $command = $commands[$i]; $err = $errs[$i]; $command_string .= "{$red}Command {$i}{$reset} ({$exit}): {$command}\n"; if ($err) { $err_string .= "{$red}Error {$i}{$reset}: {$err}\n"; } } } } else { $command_string = "{$red}Command{$reset} ({$exits}): {$commands}\n"; if ($errs) { $err_string = "{$red}Error{$reset}: {$errs}\n"; } } $reason_string = "Reason: {$reason}\n"; $dependency_string = ""; if ($missing_dependency) { $dependency_string = "NOTE: dependency {$missing_dependency} is missing. This may be the cause of this failure\n"; } $header = "{$reason_string}{$dependency_string}{$command_string}{$err_string}"; // ready the output information global $log_directory; $script_name = adjusted_name($subject); $filename = "{$log_directory}/{$test_name}/{$script_name}.log"; $dirname = dirname($filename); if (!is_dir($dirname)) { @mkdir($dirname, 0755, true); phc_assert(is_dir($dirname), "directory not created"); } if (!is_array($outs)) { $outs = array($outs); } $out_string = ""; // create the stdout logs - but only if there is more than 1 log if (count($outs) > 1 && count(array_filter($outs, "strlen"))) { foreach ($outs as $i => $out) { $output_contents = "Command: {$commands[$i]}\n" . $out; file_put_contents("{$filename}.out.{$i}", $output_contents); } } // write to the main log file foreach ($outs as $i => $out) { if (strlen($out) > 1000) { $out = substr($out, 0, 1000) . "... [truncated]\n"; } $out_string .= "{$red}Output {$i}{$reset}:\n{$out}\n"; } // print the output file_put_contents($filename, $header); file_put_contents($filename, rtrim($out_string), FILE_APPEND); file_put_contents($filename, "\n", FILE_APPEND); }
public function crear($valoracion = '') { modules::run('general/is_logged', base_url().'index.php/usuarios/iniciar-sesion'); $permiso = modules::run('general/have_permission', 21); $vista = ($permiso) ? 'crear_pcn' : 'usuario_sinpermiso'; $view['nivel'] = 21; $this->load->helper('text'); $breadcrumbs = array ( base_url() => 'Inicio', base_url().'index.php/continuidad' => 'Continuidad del Negocio', base_url().'index.php/continuidad/seleccionar_listado' => 'Seleccionar Listado', base_url().'index.php/continuidad/listado_pcn/'.$valoracion => 'Listado de PCN', '#' => 'Crear PCN' ); if($_POST) { $post = $_POST; // die_pre($post); // DELIMITADOR DE ERROR DEL FORM VALIDATION $this->form_validation->set_error_delimiters('<div class="alert alert-danger">', '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); // REGLAS DEL FORM VALIDATION if(array_key_exists('id_continuidad',$_POST)) $this->form_validation->set_rules('codigo','<strong>Código</strong>','required|xss_clean'); else $this->form_validation->set_rules('codigo','<strong>Código</strong>','required|xss_clean|is_unique[plan_continuidad.codigo]'); $this->form_validation->set_rules('denominacion','<strong>Denominación</strong>','required|xss_clean'); $this->form_validation->set_message('is_unique', 'El %s que intenta crear ya se encuentra almacenado en la base de datos'); if($this->form_validation->run($this)) { $template['pcn'] = $post; $template['amenaza'] = $this->general->get_row('riesgos_amenazas',array('id_riesgo'=>$post['id_riesgo'])); $encargado = $this->riesgos->get_personal_normal(array('id_personal'=>$post['id_empleado'])); $template['encargado'] = $encargado[0]; $equipo = array($post['id_crisis'],$post['id_recuperacion'],$post['id_logistica'],$post['id_rrpp'],$post['id_pruebas']); $template['equipos'] = $this->riesgos->get_allteams('',$equipo); foreach($template['equipos'] as $key => $equipo) { foreach ($equipo->equipo as $key => $team) { $id_involucrados[] = $team->id_personal; } } $id_involucrados = array_unique($id_involucrados); $template['involucrados'] = $this->riesgos->get_personal_normal('',$id_involucrados); $template['estrategia'] = $this->riesgos->get_allestrategias(array('id_estrategia'=>$_POST['id_estrategia'])); $template['estrategia'] = $template['estrategia'][0]; if($template['amenaza']->id_categoria == 7) { $id_servicioproceso = $this->general->get_row('proceso_riesgo',array('id_riesgo'=>$template['amenaza']->id_riesgo))->id_servicioproceso; $template['proceso'] = $this->general->get_row('servicio_proceso',array('servicio_proceso_id'=>$id_servicioproceso)); $template['servicios'] = $this->riesgos->get_servicios_fromproceso($id_servicioproceso); } // die_pre($template); $this->load->library('mpdf'); $pdf = $this->load->view('continuidad/continuidad/pdf_template.php',$template,TRUE); $mpdf = new mPDF(); $mpdf->WriteHTML($pdf); $name = reset_string($post['denominacion']); $ruta = $_SERVER['DOCUMENT_ROOT'].'/assets/back/continuidad_uploads/'.$name.'.pdf'; if(file_exists($ruta)) unlink($ruta); $post['pdf'] = $ruta; $mpdf->Output($ruta,'F'); if(isset($post['id_continuidad']) && !empty($post['id_continuidad'])) { // SI SE ESTA ACTUALIZANDO UN PCN EXISTENTE $old_pdf = $this->general->get_row('plan_continuidad',array('id_continuidad'=>$post['id_continuidad']),array('pdf')); $old_name = $this->general->get_row('plan_continuidad',array('id_continuidad'=>$post['id_continuidad']),array('denominacion')); if(!empty($old_pdf->pdf) && file_exists($old_pdf->pdf) && ($old_name->denominacion != $post['denominacion'])) unlink($old_pdf->pdf); // echo_pre($post); if($this->general->update2('plan_continuidad',$post,array('id_continuidad'=>$post['id_continuidad']))) { if($_POST['id_estado'] == 1) { $this->activar_alerta($post['id_continuidad'], $valoracion, 1); $pdf_file = $mpdf->Output($ruta,'S'); $email = new stdClass(); $email->subject = 'Activación de PCN'; $email->message = 'Se ha activado el Plan de Continuidad del Negocio '.$post['denominacion'].'<br />Se ha adjuntado un archivo PDF con los lineamientos para la ejecución del PCN'; $email->pdf = $pdf_file; $email->pdf_path = $ruta; $this->mailing($template['involucrados'], $email, $valoracion); }else { $this->activar_alerta($post['id_continuidad'], $valoracion, 0); } $this->session->set_flashdata('alert_success','Plan de Continuidad del Negocio <strong>'.$post['denominacion'].'</strong> modificado con éxito'); }else $this->session->set_flashdata('alert_error','Hubo un error al intentar modificar el Plan de Continuidad del Negocio <strong>'.$post['denominacion'].'</strong>, por favor intente de nuevo o contacte a su administrador'); }else { // SI SE CREA UN PCN NUEVO $post['fecha_creacion'] = date('Y-m-d H:i:s'); if($this->general->insert('plan_continuidad',$post)) $this->session->set_flashdata('alert_success','Nuevo Plan de Continuidad del Negocio creado con éxito'); else $this->session->set_flashdata('alert_error','Hubo un error al intentar crear el Plan de Continuidad del Negocio, por favor intente de nuevo o contacte a su administrador'); } redirect(site_url('index.php/continuidad/listado_pcn/'.$valoracion)); } } $view['estrategias'] = $this->general->get_table('estrategias_recuperacion'); $view['valoracion'] = $valoracion; $view['crisis'] = $this->riesgos->get_allteams(array('e.id_tipo'=>1)); $view['recuperacion'] = $this->riesgos->get_allteams(array('e.id_tipo'=>2)); $view['logistica'] = $this->riesgos->get_allteams(array('e.id_tipo'=>3)); $view['rrpp'] = $this->riesgos->get_allteams(array('e.id_tipo'=>4)); $view['pruebas'] = $this->riesgos->get_allteams(array('e.id_tipo'=>5)); $view['breadcrumbs'] = breadcrumbs($breadcrumbs); $view['riesgos'] = $this->riesgos->get_allrisks(array('riesgos_amenazas.valoracion'=>$valoracion)); $view['departamentos'] = $this->general->get_table('departamento'); $view['estados'] = $this->general->get_table('usuarios_estado'); $view['crearpcn_js'] = $this->load->view('continuidad/continuidad/crearpcn_js','',TRUE); $this->utils->template($this->_list1(),'continuidad/continuidad/'.$vista,$view,$this->title,'Crear nuevo PCN','two_level'); }