Changeset 67
- Timestamp:
- 03/11/2009 10:41:24 AM (3 years ago)
- File:
-
- 1 edited
-
trunk/WordPress/plugin/transposh/transposh.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/transposh.php
r64 r67 42 42 43 43 //Database version 44 define("DB_VERSION", "1.0 ");44 define("DB_VERSION", "1.01"); 45 45 46 46 //Constant used as key in options database … … 287 287 return; 288 288 } 289 289 290 290 291 291 $overlib_dir = "$plugin_url/js/overlibmws"; … … 588 588 function setup_db() 589 589 { 590 591 global $wpdb;590 logger("Enter " . __METHOD__ ); 591 global $wpdb; 592 592 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 593 593 594 $table_name = $wpdb->prefix . TRANSLATIONS_TABLE; 595 596 if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) 597 { 594 $installed_ver = get_option(TRANSPOSH_DB_VERSION); 595 596 if( $installed_ver != DB_VERSION ) { 597 $table_name = $wpdb->prefix . TRANSLATIONS_TABLE; 598 599 //if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) 600 //{ 598 601 logger("Attempting to create table $table_name", 0); 599 $sql = "CREATE TABLE " . $table_name . " (original VARCHAR(256) NOT NULL, 600 lang CHAR(5) NOT NULL, 601 translated VARCHAR(256), 602 PRIMARY KEY (original, lang)) "; 602 $sql = "CREATE TABLE $table_name (original VARCHAR(256) NOT NULL, 603 lang CHAR(5) NOT NULL, 604 translated VARCHAR(256), 605 source TINYINT NOT NULL, 606 PRIMARY KEY (original, lang)) "; 603 607 604 608 … … 606 610 607 611 //Verify that newly created table is ready for use. 608 $insert = "INSERT INTO " . $table_name . " (original, translated, lang) " . 609 "VALUES ('Hello','Hi There','zz')"; 610 611 $result = $wpdb->query($insert); 612 613 if($result === FALSE) 614 { 615 logger("Error failed to create $table_name !!!", 0); 616 } 617 else 618 { 619 logger("Table $table_name was created successfuly", 0); 620 add_option(TRANSPOSH_DB_VERSION, DB_VERSION); 621 } 622 } 623 624 $table_name = $wpdb->prefix . TRANSLATIONS_LOG; 625 626 if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) 627 { 612 //$insert = "INSERT INTO " . $table_name . " (original, translated, lang) " . 613 //"VALUES ('Hello','Hi There','zz')"; 614 615 //$result = $wpdb->query($insert); 616 617 //if($result === FALSE) 618 //{ 619 //logger("Error failed to create $table_name !!!", 0); 620 //} 621 //else 622 //{ 623 // logger("Table $table_name was created successfuly", 0); 624 //} 625 //} 626 627 $table_name = $wpdb->prefix . TRANSLATIONS_LOG; 628 629 //if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) 630 //{ 628 631 logger("Attempting to create table $table_name", 0); 629 632 $sql = "CREATE TABLE " . $table_name . " (original VARCHAR(256) NOT NULL, … … 636 639 637 640 dbDelta($sql); 641 // TODO: check 642 update_option(TRANSPOSH_DB_VERSION, DB_VERSION); 638 643 } 639 644 … … 731 736 logger("Enter " . __METHOD__, 3); 732 737 738 $db_version = get_option(TRANSPOSH_DB_VERSION); 739 740 if ($db_version != DB_VERSION) 741 { 742 setup_db(); 743 //$admin_msg = "Translation database version ($db_version) is not comptabile with this plugin (". DB_VERSION . ") <br>"; 744 745 logger("Updating database in plugin loaded", 0); 746 //Some error occured - notify admin and deactivate plugin 747 //add_action('admin_notices', 'plugin_install_error'); 748 } 749 750 // TODO: This is wrong? and also deactivation fails 733 751 if (get_option(TRANSPOSH_DB_VERSION) == NULL) 734 752 { … … 740 758 } 741 759 742 $db_version = get_option(TRANSPOSH_DB_VERSION); 743 744 if ($db_version != DB_VERSION) 745 { 746 $admin_msg = "Translation database version ($db_version) is not comptabile with this plugin (". DB_VERSION . ") <br>"; 747 748 logger("Messsage to admin: $admin_msg", 0); 749 //Some error occured - notify admin and deactivate plugin 750 add_action('admin_notices', 'plugin_install_error'); 751 } 752 } 753 754 /* 755 * Gets the plugin name to be used in activation/decativation hooks. 760 } 761 762 /* 763 * Gets the plugin name to be used in activation/decativation hooks. 756 764 * Keep only the file name and its containing directory. Don't use the full 757 * path as it will break when using symbollic links. 765 * path as it will break when using symbollic links. 758 766 */ 759 767 function get_plugin_name() 760 768 { 761 $file = __FILE__; 769 $file = __FILE__; 762 770 $file = str_replace('\\','/',$file); // sanitize for Win32 installs 763 771 $file = preg_replace('|/+|','/', $file); // remove any duplicate slash 764 772 765 773 //keep only the file name and its parent directory 766 774 $file = preg_replace('/.*\/([^\/]+\/[^\/]+)$/', '$1', $file);
Note: See TracChangeset
for help on using the changeset viewer.
