/** * * @global wpdb $wpdb * @param string $sql_file_to_execute * @param string $prefix */ function update_tables($sql_file_to_execute, $prefix) { // read the sql file global $wpdb; try { $f = fopen($sql_file_to_execute, 'r'); if ($f === false) { error_log("Unable to open " . $sql_file_to_execute, 0); trigger_error("Unable to open " . $sql_file_to_execute, E_USER_ERROR); throw new Exception("Unable to open " . $sql_file_to_execute); } else { $sql_file = fread($f, filesize($sql_file_to_execute)); $sql_array = explode(';', $sql_file); $sql_error_code = 0; $sql_error_text = null; foreach ($sql_array as $stmt) { $stmt = trim($stmt); if (strlen($stmt) > 3 && substr(ltrim($stmt), 0, 2) != '/*') { if ($prefix != null) { $stmt = str_replace('EXISTS rp_', 'EXISTS ' . $prefix . 'rp_', $stmt); $stmt = str_replace('TABLE rp_', 'TABLE ' . $prefix . 'rp_', $stmt); $stmt = str_replace('TRUNCATE rp_', 'TRUNCATE ' . $prefix . 'rp_', $stmt); $stmt = str_replace('INTO rp_', 'INTO ' . $prefix . 'rp_', $stmt); } $result = $wpdb->query($stmt); if ($result === false) { $wpdb->print_error(); throw new Exception($stmt); } } } } } catch (Exception $e) { error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0); trigger_error($e->getMessage(), E_USER_ERROR); throw new Exception($e); } }
/** * * @param RP_Source_Record $source */ function update_src_notes($source) { RP_Dao_Factory::get_rp_source_note_dao($this->credentials->prefix)->delete_by_src($source->id, $this->batch_id); foreach ($source->notes as $note) { $src_note = new RP_Source_Note(); $src_note->source_id = $source->id; $src_note->source_batch_id = $this->batch_id; $src_note->note_rec_id = $note->id; $src_note->note = $note->text; try { $id = RP_Dao_Factory::get_rp_source_note_dao($this->credentials->prefix)->insert($src_note); } catch (Exception $e) { error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0); echo $e->getMessage(); throw $e; } } }
/** * * @param string $plugin_dir * @param string $version * @param array $options * @param string $prefix */ function persona_upgrade($plugin_dir, $version, $options, $prefix) { global $wpdb; if ($options['version'] < '2.0.3') { unset($options['evidence_page']); unset($options['index_page']); } if ($options['version'] < '2.2.0') { $options['hide_descendancy'] = 0; } if ($options['version'] < '3.0.0') { $stmt = "CREATE TABLE IF NOT EXISTS rp_indi_seq (id INT NOT NULL)"; if ($prefix != null) { $stmt = str_replace('rp_', $prefix . 'rp_', $stmt); } $result = $wpdb->query($stmt); if ($result === false) { $wpdb->print_error(); throw new Exception($stmt); } $stmt = "INSERT INTO rp_indi_seq VALUES (100000)"; if ($prefix != null) { $stmt = str_replace('INTO rp_', 'INTO ' . $prefix . 'rp_', $stmt); } $result = $wpdb->query($stmt); if ($result === false) { $wpdb->print_error(); //throw new Exception( $stmt ); } $stmt = "CREATE TABLE IF NOT EXISTS rp_fam_seq (id INT NOT NULL)"; if ($prefix != null) { $stmt = str_replace('rp_', $prefix . 'rp_', $stmt); } $result = $wpdb->query($stmt); if ($result === false) { $wpdb->print_error(); throw new Exception($stmt); } $stmt = "INSERT INTO rp_fam_seq VALUES (100000)"; if ($prefix != null) { $stmt = str_replace('INTO rp_', 'INTO ' . $prefix . 'rp_', $stmt); } $result = $wpdb->query($stmt); if ($result === false) { $wpdb->print_error(); //throw new Exception( $stmt ); } } // support table recreation on activation try { $credentials = new RP_Credentials(); $credentials->set_prefix($wpdb->prefix); $transaction = new RP_Transaction($credentials, true); RP_Dao_Factory::get_rp_persona_dao($credentials->prefix)->get_batch_ids(); $transaction->close(); } catch (Exception $e) { if (strpos($e->getMessage(), "doesn't exist") >= 0) { $creator = new RP_Table_Creator(); $creator->update_tables($this->sql_file_to_create_tables, $prefix); } else { error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0); throw $e; } } $options['version'] = $version; update_option('persona_plugin', $options); }
/** * * @return string */ function build_roots_tools_page() { try { if (isset($_GET['rootspage'])) { $page = $_GET['rootspage']; if ($page == 'upload') { echo $this->upload_gedcom_handler(); } else { if ($page == 'create') { echo $this->add_page_handler(); } else { if ($page == 'include') { echo $this->include_page_handler(); } else { if ($page == 'edit') { echo $this->edit_persona_page_handler(); } else { if ($page == 'util') { echo $this->utility_page_handler(); } } } } } } else { $this->transaction = new RP_Transaction($this->credentials, true); $batch_ids = RP_Dao_Factory::get_rp_persona_dao($this->credentials->prefix)->get_batch_ids(); $this->transaction->close(); $options = get_option('persona_plugin'); $options['home_url'] = home_url(); $builder = new RP_Tools_Page_Builder(); echo $builder->build($options, $batch_ids); } } catch (Exception $e) { error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0); echo '<span style="color:red;margin-top:20px;display:inline-block;">' . $e->getMessage() . "::" . RP_Persona_Helper::trace_caller() . '</span>'; } }
/** * Reads a file into an array. * Validates the contents of the file. * Parses the records into a tree of nodes. * Parses the tree into objects. * * @param string $Filename name of file to be parsed * * @return void * @throws FileException * @access public * @since Method available since Release 0.0.1 */ public function parse($_filename, $callback_class = null) { @ini_set('auto_detect_line_endings', true); $this->gedcom_filename = $_filename; $callback = $callback_class === null ? $this : $callback_class; $line = null; try { if (($fp = fopen($this->gedcom_filename, 'r')) !== false) { $buffer = array(); $next_line = $this->import_header($fp, array($callback, 'process_header')); while (true) { $buffer[] = $this->convert_to_utf8($next_line); while (!feof($fp)) { $line = trim(fgets($fp, 1024)); if ($line != '' && $line[0] != '0') { $buffer[] = $this->convert_to_utf8($line); } else { $gedcom_tree = null; $this->create_tree($buffer, 0, 0, $gedcom_tree); $this->parse_tree($gedcom_tree, $callback); unset($buffer); unset($gedcom_tree); set_time_limit(60); $next_line = $line; break; } } if ($line === null) { $line = $next_line; } if (strpos($line, '0 TRLR') !== false) { fclose($fp); break; } else { if (feof($fp)) { fclose($fp); throw new RP_File_Exception('Invalid GEDCOM file: invalid TRLR record.'); } } } } else { throw new RP_File_Exception('Cannot open file ' . $this->gedcom_filename); } } catch (Exception $e) { error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(), 0); throw $e; } }