Changeset 648423
- Timestamp:
- 01/05/2013 06:38:24 PM (13 years ago)
- Location:
- rootspersona/trunk
- Files:
-
- 5 edited
-
php/class-RP-Persona-Installer.php (modified) (1 diff)
-
php/class-RP-Persona-Site-Mender.php (modified) (1 diff)
-
php/class-RP-Table-Creator.php (modified) (1 diff)
-
php/dao/mysql/class-RP-Mysql-DAO.php (modified) (2 diffs)
-
rootspersona.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
rootspersona/trunk/php/class-RP-Persona-Installer.php
r640898 r648423 28 28 } else { 29 29 $creator = new RP_Table_Creator(); 30 $creator->update_tables( $this->sql_file_to_create_tables, $prefix ); 31 30 try { 31 $creator->update_tables( $this->sql_file_to_create_tables, $prefix ); 32 } catch (Exception $e) { 33 error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(),0); 34 trigger_error($e->getMessage(), E_USER_ERROR); 35 } 32 36 $options = array(); 33 37 $options['version'] = $version; -
rootspersona/trunk/php/class-RP-Persona-Site-Mender.php
r640898 r648423 32 32 33 33 $queryOnly = $is_repair === true ? false : true; 34 35 $this->transaction = new RP_Transaction( $this->credentials, $queryOnly ); 34 $this->transaction = new RP_Transaction( $this->credentials, $queryOnly ); 36 35 $parent = $options['parent_page']; 37 36 foreach ( $pages as $page ) { -
rootspersona/trunk/php/class-RP-Table-Creator.php
r539248 r648423 12 12 // read the sql file 13 13 global $wpdb; 14 $f = fopen( $sql_file_to_execute, 'r+' ); 15 $sql_file = fread( $f, filesize( $sql_file_to_execute ) ); 16 $sql_array = explode( ';', $sql_file ); 17 $sql_error_code = 0; 18 $sql_error_text = null; 19 foreach ( $sql_array as $stmt ) { 20 $stmt = trim( $stmt ); 21 if ( strlen( $stmt ) > 3 22 && substr( ltrim( $stmt ), 0, 2 ) != '/*' ) { 23 if ( $prefix != null ) { 24 $stmt = str_replace( 'EXISTS rp_', 'EXISTS ' . $prefix . 'rp_', $stmt ); 25 $stmt = str_replace( 'TABLE rp_', 'TABLE ' . $prefix . 'rp_', $stmt ); 26 $stmt = str_replace( 'TRUNCATE rp_', 'TRUNCATE ' . $prefix . 'rp_', $stmt ); 27 $stmt = str_replace( 'INTO rp_', 'INTO ' . $prefix . 'rp_', $stmt ); 28 } 29 $result = $wpdb->query( $stmt ); 30 if ( $result === false ) { 31 $wpdb->print_error(); 32 throw new Exception( $stmt ); 14 try { 15 $f = fopen( $sql_file_to_execute, 'r' ); 16 if( $f === false) { 17 error_log("Unable to open " . $sql_file_to_execute ,0); 18 trigger_error("Unable to open " . $sql_file_to_execute, E_USER_ERROR); 19 throw new Exception( "Unable to open " . $sql_file_to_execute ); 20 } else { 21 $sql_file = fread( $f, filesize( $sql_file_to_execute ) ); 22 $sql_array = explode( ';', $sql_file ); 23 $sql_error_code = 0; 24 $sql_error_text = null; 25 foreach ( $sql_array as $stmt ) { 26 $stmt = trim( $stmt ); 27 if ( strlen( $stmt ) > 3 28 && substr( ltrim( $stmt ), 0, 2 ) != '/*' ) { 29 if ( $prefix != null ) { 30 $stmt = str_replace( 'EXISTS rp_', 'EXISTS ' . $prefix . 'rp_', $stmt ); 31 $stmt = str_replace( 'TABLE rp_', 'TABLE ' . $prefix . 'rp_', $stmt ); 32 $stmt = str_replace( 'TRUNCATE rp_', 'TRUNCATE ' . $prefix . 'rp_', $stmt ); 33 $stmt = str_replace( 'INTO rp_', 'INTO ' . $prefix . 'rp_', $stmt ); 34 } 35 $result = $wpdb->query( $stmt ); 36 if ( $result === false ) { 37 $wpdb->print_error(); 38 throw new Exception( $stmt ); 39 } 40 } 33 41 } 34 42 } 43 } catch (Exception $e) { 44 error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(),0); 45 trigger_error($e->getMessage(), E_USER_ERROR); 46 throw new Exception($e); 35 47 } 36 48 } -
rootspersona/trunk/php/dao/mysql/class-RP-Mysql-DAO.php
r504051 r648423 1 1 <?php 2 2 3 /** 3 4 * @todo Description of class RP_RpMySqlDAO … … 13 14 */ 14 15 class RP_Mysql_DAO { 15 var $prefix;16 16 17 function __construct( $prefix ) { 18 $this->prefix = $prefix; 19 } 20 21 public function load( $table_name, $id_col, $batch_col, $id, $batch_id ) { 22 $sql = "SELECT * FROM $table_name WHERE $id_col = $id AND $batch_col = $batch_id"; 23 $sql_query = new RP_Sql_Query( $sql, $this->prefix ); 24 return $this->get_row( $sql_query ); 25 } 17 var $prefix; 26 18 27 public function query_all($table_name) { 28 $sql = 'SELECT * FROM ' . $table_name; 29 $sql_query = new RP_Sql_Query( $sql, $this->prefix ); 30 return $this->get_list( $sql_query ); 31 } 19 function __construct($prefix) { 20 $this->prefix = $prefix; 21 } 32 22 33 public function query_all_order_by( $table_name, $order_column) {34 $sql = 'SELECT * FROM '. $table_name . ' ORDER BY ' . $order_column;35 $sql_query = new RP_Sql_Query( $sql, $this->prefix);36 return $this->get_list( $sql_query);37 }23 public function load($table_name, $id_col, $batch_col, $id, $batch_id) { 24 $sql = "SELECT * FROM $table_name WHERE $id_col = $id AND $batch_col = $batch_id"; 25 $sql_query = new RP_Sql_Query($sql, $this->prefix); 26 return $this->get_row($sql_query); 27 } 38 28 39 public function delete( $table_name, $id_col, $batch_col, $id, $batch_id ) { 40 $sql = "DELETE FROM $table_name WHERE $id_col = $id AND $batch_col = $batch_id"; 41 $sql_query = new RP_Sql_Query( $sql, $this->prefix ); 42 $sql_query->set( $id ); 43 $sql_query->set_number( $batch_id ); 44 return $this->execute_update( $sql_query ); 45 } 46 47 protected function get_row( $sql_query ) { 48 $tab = RP_Query_Executor::execute( $sql_query ); 49 if ( count( $tab ) == 0 ) { 50 return null; 51 } 52 return $this->read_row( $tab[0] ); 53 } 54 55 protected function get_list( $sql_query ) { 56 $tab = RP_Query_Executor::execute( $sql_query ); 57 $ret = array(); 58 for ( $i = 0; $i < count( $tab ); $i++ ) { 59 $ret[$i] = $this->read_row( $tab[$i] ); 60 } 61 return $ret; 62 } 63 64 public function clean( $table_name ) { 65 $sql = 'DELETE FROM ' . $table_name; 66 $sql_query = new RP_Sql_Query( $sql, $this->prefix ); 67 return $this->execute_update( $sql_query ); 68 } 29 public function query_all($table_name) { 30 $sql = 'SELECT * FROM ' . $table_name; 31 $sql_query = new RP_Sql_Query($sql, $this->prefix); 32 return $this->get_list($sql_query); 33 } 69 34 70 protected function execute( $sql_query ) { 71 return RP_Query_Executor::execute( $sql_query ); 72 } 35 public function query_all_order_by($table_name, $order_column) { 36 $sql = 'SELECT * FROM ' . $table_name . ' ORDER BY ' . $order_column; 37 $sql_query = new RP_Sql_Query($sql, $this->prefix); 38 return $this->get_list($sql_query); 39 } 73 40 74 protected function execute_update( $sql_query ) { 75 return RP_Query_Executor::execute_update( $sql_query ); 76 } 41 public function delete($table_name, $id_col, $batch_col, $id, $batch_id) { 42 $sql = "DELETE FROM $table_name WHERE $id_col = $id AND $batch_col = $batch_id"; 43 $sql_query = new RP_Sql_Query($sql, $this->prefix); 44 $sql_query->set($id); 45 $sql_query->set_number($batch_id); 46 return $this->execute_update($sql_query); 47 } 77 48 78 protected function query_single_result( $sql_query ) { 79 return RP_Query_Executor::query_for_string( $sql_query ); 80 } 49 protected function get_row($sql_query) { 50 $tab = RP_Query_Executor::execute($sql_query); 51 if (count($tab) == 0) { 52 return null; 53 } 54 return $this->read_row($tab[0]); 55 } 81 56 82 protected function execute_insert( $sql_query ) { 83 return RP_Query_Executor::execute_insert( $sql_query ); 84 } 57 protected function get_list($sql_query) { 58 $tab = RP_Query_Executor::execute($sql_query); 59 $ret = array(); 60 for ($i = 0; $i < count($tab); $i++) { 61 $ret[$i] = $this->read_row($tab[$i]); 62 } 63 return $ret; 64 } 65 66 public function clean($table_name) { 67 $sql = 'DELETE FROM ' . $table_name; 68 $sql_query = new RP_Sql_Query($sql, $this->prefix); 69 return $this->execute_update($sql_query); 70 } 71 72 protected function execute($sql_query) { 73 return RP_Query_Executor::execute($sql_query); 74 } 75 76 protected function execute_update($sql_query) { 77 return RP_Query_Executor::execute_update($sql_query); 78 } 79 80 protected function query_single_result($sql_query) { 81 return RP_Query_Executor::query_for_string($sql_query); 82 } 83 84 protected function execute_insert($sql_query) { 85 return RP_Query_Executor::execute_insert($sql_query); 86 } 87 85 88 } -
rootspersona/trunk/rootspersona.php
r646505 r648423 530 530 . $location . '"; </script>'; 531 531 } else { 532 533 $this->transaction = new RP_Transaction( $this->credentials, true ); 532 $this->transaction = new RP_Transaction( $this->credentials, true ); 534 533 $batch_ids = RP_Dao_Factory::get_rp_persona_dao( $this->credentials->prefix ) 535 534 ->get_batch_ids( ); … … 664 663 error_log($e->getMessage() . "::" . RP_Persona_Helper::trace_caller(),0); 665 664 trigger_error($e->getMessage(), E_USER_ERROR); 665 throw new Exception($e); 666 } 667 $sql = "SELECT COUNT(1) FROM information_schema.tables WHERE table_schema='" 668 . DB_NAME 669 . "' AND table_name='" 670 . $wpdb->prefix . "rp_fam'"; 671 $sql_query = new RP_Sql_Query($sql, $wpdb->prefix); 672 $tab = RP_Query_Executor::execute( $sql_query, $this->credentials ); 673 if($tab[0][0] !== "1") { 674 error_log("RootsPersona tables not created.",0); 675 trigger_error("RootsPersona tables not created.", E_USER_ERROR); 676 throw new Exception("RootsPersona tables not created."); 666 677 } 667 678 }
Note: See TracChangeset
for help on using the changeset viewer.