| 41 | | $expected_tables = array ( |
| | 41 | $expected_tables = getExpectedTables(); |
| | 42 | |
| | 43 | $rs = rss_query( "show tables", true, true ); |
| | 44 | while(list($tbl) = rss_fetch_row($rs)) { |
| | 45 | $actual_tables[]=$tbl; |
| | 46 | } |
| | 47 | |
| | 48 | foreach ($expected_tables as $base => $tbl) { |
| | 49 | $exists = array_search($tbl,$actual_tables); |
| | 50 | if ($exists === FALSE || $exists === NULL) { |
| | 51 | $missing_tables[]=$base; |
| | 52 | } |
| | 53 | } |
| | 54 | |
| | 55 | $updated = 0; |
| | 56 | if (count($missing_tables) > 0) { |
| | 57 | $msg = (count($actual_tables)?"Updating":"Creating") |
| | 58 | .' your database schema! This should be a one-time operation,' |
| | 59 | .' if you see this message over and over again please import your database schema' |
| | 60 | .' manually.'; |
| | 61 | rss_error($msg, RSS_ERROR_WARNING); |
| | 62 | |
| | 63 | foreach($missing_tables as $table) { |
| | 64 | $updated += call_user_func("_init_$table"); |
| | 65 | } |
| | 66 | |
| | 67 | if ($updated == count($missing_tables)) { |
| | 68 | rss_error(__("Successfully created $updated of $updated database tables!"), RSS_ERROR_NOTICE); |
| | 69 | } else { |
| | 70 | rss_error( |
| | 71 | (count($missing_tables) - $updated) . " out of " |
| | 72 | . count($missing_tables) ." tables could not be created!",RSS_ERROR_ERROR); |
| | 73 | } |
| | 74 | } |
| | 75 | |
| | 76 | if ($updated) { |
| | 77 | rss_invalidate_cache(); |
| | 78 | } |
| | 79 | return $updated; |
| | 80 | } |
| | 81 | |
| | 82 | function getExpectedTables() { |
| | 83 | $expected_tables = array ( |
| 58 | | |
| 59 | | $rs = rss_query( "show tables", true, true ); |
| 60 | | while(list($tbl) = rss_fetch_row($rs)) { |
| 61 | | $actual_tables[]=$tbl; |
| 62 | | } |
| 63 | | |
| 64 | | foreach ($expected_tables as $base => $tbl) { |
| 65 | | $exists = array_search($tbl,$actual_tables); |
| 66 | | if ($exists === FALSE || $exists === NULL) { |
| 67 | | $missing_tables[]=$base; |
| 68 | | } |
| 69 | | } |
| 70 | | $updated = 0; |
| 71 | | if (count($missing_tables) > 0) { |
| 72 | | $msg = (count($actual_tables)?"Updating":"Creating") |
| 73 | | .' your database schema! This should be a one-time operation,' |
| 74 | | .' if you see this message over and over again please import your database schema' |
| 75 | | .' manually.'; |
| 76 | | rss_error($msg, RSS_ERROR_WARNING); |
| 77 | | |
| 78 | | foreach($missing_tables as $table) { |
| 79 | | $updated += call_user_func("_init_$table"); |
| 80 | | } |
| 81 | | |
| 82 | | if ($updated == count($missing_tables)) { |
| 83 | | rss_error("Successfully created $updated of $updated database tables!", RSS_ERROR_NOTICE); |
| 84 | | } else { |
| 85 | | rss_error( |
| 86 | | (count($missing_tables) - $updated) . " out of " |
| 87 | | . count($missing_tables) ." tables could not be created!",RSS_ERROR_ERROR); |
| 88 | | } |
| 89 | | } |
| 90 | | |
| 91 | | if ($updated) { |
| 92 | | rss_invalidate_cache(); |
| 93 | | } |
| 94 | | return $updated; |
| | 97 | return $expected_tables; |
| 461 | | "rss.output.lang" => array("en,es,fr,dk,it,pt_BR,se,0","en,es,fr,dk,it,pt_BR,se,0","enum","Language pack to use.",NULL), |
| | 464 | "rss.output.lang" => array("en_US,cn_ZH,de_DE,dk_DK,es_ES,fr_FR,he_IL,it_IT,ja_JP,pt_BR,pt_PT,ru_RU,sv_SV,0","en_US,cn_ZH,de_DE,dk_DK,es_ES,fr_FR,he_IL,it_IT,ja_JP,pt_BR,pt_PT,ru_RU,sv_SV,0","enum","Language pack to use.",NULL), |
| 705 | | $table = getTable('item2user'); |
| 706 | | rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true); |
| 707 | | $sql_create = str_replace('__table__',$table, <<< _SQL_ |
| 708 | | CREATE TABLE __table__ ( |
| 709 | | fkiid bigint(16) NOT NULL, |
| 710 | | fkuid bigint(16) NOT NULL, |
| 711 | | fkcid bigint(11) NOT NULL, |
| 712 | | flgunread tinyint(1) NOT NULL default '1', |
| 713 | | flgsticky tinyint(1) NOT NULL default '0', |
| 714 | | flgprivate tinyint(1) NOT NULL default '0', |
| 715 | | flgdeleted tinyint(1) NOT NULL default '0', |
| 716 | | flgflagged tinyint(1) NOT NULL default '0', |
| 717 | | KEY flgunread (flgunread), |
| 718 | | KEY flgsticky (flgsticky), |
| 719 | | KEY flgprivate (flgprivate), |
| 720 | | KEY flgdeleted (flgdeleted), |
| 721 | | KEY flgflagged (flgflagged), |
| 722 | | KEY fkuid (fkuid), |
| 723 | | KEY iids (fkiid) |
| 724 | | ) ENGINE=MyISAM; |
| 725 | | _SQL_ |
| 726 | | ); |
| 727 | | |
| 728 | | rss_query_wrapper($sql_create, false, true); |
| 729 | | |
| 730 | | if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { |
| 731 | | rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); |
| 732 | | return 0; |
| 733 | | } else { |
| 734 | | $fillSql = "insert into $table (fkiid,fkuid,fkcid,flgunread,flgsticky,flgprivate,flgdeleted,flgflagged) " |
| 735 | | ."select id, " . rss_user_id() . ", cid, " |
| 736 | | ." unread & ".RSS_MODE_UNREAD_STATE." = ".RSS_MODE_UNREAD_STATE.", " |
| 737 | | ." unread & ".RSS_MODE_STICKY_STATE." = ".RSS_MODE_STICKY_STATE.", " |
| 738 | | ." unread & ".RSS_MODE_PRIVATE_STATE." = ".RSS_MODE_PRIVATE_STATE.", " |
| 739 | | ." unread & ".RSS_MODE_DELETED_STATE." = ".RSS_MODE_DELETED_STATE.", " |
| 740 | | ." unread & ".RSS_MODE_FLAG_STATE." = ".RSS_MODE_FLAG_STATE." from " .getTable('item'); |
| 741 | | rss_query_wrapper($fillSql, false, true); |
| 742 | | |
| 743 | | return rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR); |
| 744 | | } |
| | 707 | $table = getTable('item2user'); |
| | 708 | rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true); |
| | 709 | $sql_create = str_replace('__table__',$table, <<< _SQL_ |
| | 710 | CREATE TABLE __table__ ( |
| | 711 | fkiid bigint(16) NOT NULL, |
| | 712 | fkuid bigint(16) NOT NULL, |
| | 713 | fkcid bigint(11) NOT NULL, |
| | 714 | flgunread tinyint(1) NOT NULL default '1', |
| | 715 | flgsticky tinyint(1) NOT NULL default '0', |
| | 716 | flgprivate tinyint(1) NOT NULL default '0', |
| | 717 | flgdeleted tinyint(1) NOT NULL default '0', |
| | 718 | flgflagged tinyint(1) NOT NULL default '0', |
| | 719 | KEY flgunread (flgunread), |
| | 720 | KEY flgsticky (flgsticky), |
| | 721 | KEY flgprivate (flgprivate), |
| | 722 | KEY flgdeleted (flgdeleted), |
| | 723 | KEY flgflagged (flgflagged), |
| | 724 | KEY fkuid (fkuid), |
| | 725 | KEY iids (fkiid) |
| | 726 | ) ENGINE=MyISAM; |
| | 727 | _SQL_ |
| | 728 | ); |
| | 729 | |
| | 730 | rss_query_wrapper($sql_create, false, true); |
| | 731 | |
| | 732 | if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { |
| | 733 | rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); |
| | 734 | return 0; |
| | 735 | } else { |
| | 736 | $fillSql = "insert into $table (fkiid,fkuid,fkcid,flgunread,flgsticky,flgprivate,flgdeleted,flgflagged) " |
| | 737 | ."select id, " . rss_user_id() . ", cid, " |
| | 738 | ." unread & ".RSS_MODE_UNREAD_STATE." = ".RSS_MODE_UNREAD_STATE.", " |
| | 739 | ." unread & ".RSS_MODE_STICKY_STATE." = ".RSS_MODE_STICKY_STATE.", " |
| | 740 | ." unread & ".RSS_MODE_PRIVATE_STATE." = ".RSS_MODE_PRIVATE_STATE.", " |
| | 741 | ." unread & ".RSS_MODE_DELETED_STATE." = ".RSS_MODE_DELETED_STATE.", " |
| | 742 | ." unread & ".RSS_MODE_FLAG_STATE." = ".RSS_MODE_FLAG_STATE." from " .getTable('item'); |
| | 743 | rss_query_wrapper($fillSql, false, true); |
| | 744 | |
| | 745 | return rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR); |
| | 746 | } |
| 750 | | $table = getTable('channels2user'); |
| 751 | | rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true); |
| 752 | | $sql_create = str_replace('__table__',$table, <<< _SQL_ |
| 753 | | CREATE TABLE __table__ ( |
| 754 | | id bigint(16) not null auto_increment, |
| 755 | | fkcid bigint(16) NOT NULL, |
| 756 | | fkuid bigint(16) NOT NULL, |
| 757 | | icon varchar(255) default NULL, |
| 758 | | position int(11) NOT NULL default '0', |
| 759 | | parent tinyint(4) default '0', |
| 760 | | flgprivate tinyint(1) NOT NULL default '0', |
| 761 | | flgdeleted tinyint(1) not null default '0', |
| 762 | | primary key (id), |
| 763 | | KEY flgprivate (flgprivate), |
| 764 | | KEY flgdeleted (flgdeleted), |
| 765 | | KEY fkuid (fkuid), |
| 766 | | KEY iids (fkcid) |
| 767 | | ) ENGINE=MyISAM; |
| 768 | | _SQL_ |
| 769 | | ); |
| 770 | | |
| 771 | | |
| 772 | | rss_query_wrapper($sql_create, false, true); |
| 773 | | |
| 774 | | if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { |
| 775 | | rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); |
| 776 | | return 0; |
| 777 | | } else { |
| 778 | | $fillSql = "insert into $table " |
| 779 | | ." (fkcid,fkuid,icon,position,parent,flgprivate,flgdeleted) " |
| 780 | | ."select id, " . rss_user_id() . ", icon, position, parent, " |
| 781 | | ." mode & ".RSS_MODE_PRIVATE_STATE." = ".RSS_MODE_PRIVATE_STATE.", " |
| 782 | | ." mode & ".RSS_MODE_DELETED_STATE." = ".RSS_MODE_DELETED_STATE." " |
| 783 | | ." from " .getTable('channels') |
| 784 | | ." where url != ''"; |
| 785 | | //die($fillSql); |
| 786 | | rss_query_wrapper($fillSql, false, true); |
| 787 | | |
| 788 | | rss_query( |
| 789 | | 'update ' .getTable('metatag') .' m ' |
| 790 | | .'set m.fkuid=' .rss_user_id()); |
| 791 | | /* |
| 792 | | $rs = rss_query( "select id, fkcid from " .getTable('channels2user')); |
| 793 | | $cids=array(); |
| 794 | | while(list($c2uid,$cid) = rss_fetch_row($rs)) { |
| 795 | | $cids[$cid]=$c2uid; |
| 796 | | } |
| 797 | | */ |
| 798 | | return rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR); |
| 799 | | } |
| 800 | | } |
| 801 | | |
| 802 | | |
| 803 | | |
| 804 | | |
| 805 | | /////////////////////////////////////////////////////////////////////////////// |
| | 752 | $table = getTable('channels2user'); |
| | 753 | rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true); |
| | 754 | $sql_create = str_replace('__table__',$table, <<< _SQL_ |
| | 755 | CREATE TABLE __table__ ( |
| | 756 | id bigint(16) not null auto_increment, |
| | 757 | fkcid bigint(16) NOT NULL, |
| | 758 | fkuid bigint(16) NOT NULL, |
| | 759 | icon varchar(255) default NULL, |
| | 760 | position int(11) NOT NULL default '0', |
| | 761 | parent tinyint(4) default '0', |
| | 762 | flgprivate tinyint(1) NOT NULL default '0', |
| | 763 | flgdeleted tinyint(1) not null default '0', |
| | 764 | primary key (id), |
| | 765 | KEY flgprivate (flgprivate), |
| | 766 | KEY flgdeleted (flgdeleted), |
| | 767 | KEY fkuid (fkuid), |
| | 768 | KEY iids (fkcid) |
| | 769 | ) ENGINE=MyISAM; |
| | 770 | _SQL_ |
| | 771 | ); |
| | 772 | |
| | 773 | |
| | 774 | rss_query_wrapper($sql_create, false, true); |
| | 775 | |
| | 776 | if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { |
| | 777 | rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); |
| | 778 | return 0; |
| | 779 | } else { |
| | 780 | $fillSql = "insert into $table " |
| | 781 | ." (fkcid,fkuid,icon,position,parent,flgprivate,flgdeleted) " |
| | 782 | ."select id, " . rss_user_id() . ", icon, position, parent, " |
| | 783 | ." mode & ".RSS_MODE_PRIVATE_STATE." = ".RSS_MODE_PRIVATE_STATE.", " |
| | 784 | ." mode & ".RSS_MODE_DELETED_STATE." = ".RSS_MODE_DELETED_STATE." " |
| | 785 | ." from " .getTable('channels') |
| | 786 | ." where url != ''"; |
| | 787 | //die($fillSql); |
| | 788 | rss_query_wrapper($fillSql, false, true); |
| | 789 | |
| | 790 | rss_query( |
| | 791 | 'update ' .getTable('metatag') .' m ' |
| | 792 | .'set m.fkuid=' .rss_user_id()); |
| | 793 | /* |
| | 794 | $rs = rss_query( "select id, fkcid from " .getTable('channels2user')); |
| | 795 | $cids=array(); |
| | 796 | while(list($c2uid,$cid) = rss_fetch_row($rs)) { |
| | 797 | $cids[$cid]=$c2uid; |
| | 798 | } |
| | 799 | */ |
| | 800 | return rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR); |
| | 801 | } |
| | 802 | } |
| | 803 | |
| | 804 | |
| | 805 | |
| | 806 | |
| | 807 | /////////////////////////////////////////////////////////////////////////////// |
| | 808 | |