Show
Ignore:
Timestamp:
10/16/06 06:31:35 (2 years ago)
Author:
mdodoo
Message:

Sync with trunk up to (but not including changeset [1585]). I should *definitely* do this more often, because this was really annoying.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/multiuser/schema.php

    r1541 r1604  
    3939    $missing_tables = array(); 
    4040    $actual_tables=array(); 
    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 
     82function getExpectedTables() { 
     83$expected_tables = array ( 
    4284        "channels" => trim(getTable("channels")), 
    4385        "config" => trim(getTable("config")), 
     
    5193        "dashboard" => trim(getTable("dashboard")), 
    5294        "properties" => trim(getTable("properties")), 
    53         "item2user" => trim(getTable("item2user")), 
    54         "channels2user" => trim(getTable("channels2user")), 
    55  
    5695 
    5796    ); 
    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; 
    9598} 
    9699 
     
    261264            // guid of an item - added in 0.5.3 
    262265            rss_query('alter table ' . getTable('item') . ' add column guid text null'); 
    263             rss_query('alter table ' . getTable('item') . " add index 'guid' ('guid'(10))"); 
     266            rss_query('alter table ' . getTable('item') . ' add index `guid` (`guid`(10))'); 
    264267            if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    265268                $updated++; 
     
    272275        break; 
    273276        case 'm.fkuid': 
    274             // userid on metatags - added in 0.5.5 
    275             rss_query('alter table ' . getTable('metatag') . ' add column fkuid bigint(15) not null'); 
    276             rss_query('alter table ' . getTable('metatag') . " add index 'fkuid' ('fkuid')"); 
    277             if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    278                 $updated++; 
    279                 rss_error('updated schema for table ' . getTable('metatag'), RSS_ERROR_NOTICE); 
    280             } else { 
    281                 rss_error('Failed updating schema for table ' . getTable('metatag') . ': ' 
    282                     . rss_sql_error_message(), RSS_ERROR_ERROR); 
    283             } 
    284          
    285         break;       
     277                       // userid on metatags - added in 0.5.5 
     278                       rss_query('alter table ' . getTable('metatag') . ' add column fkuid bigint(15) not null'); 
     279                       rss_query('alter table ' . getTable('metatag') . " add index 'fkuid' ('fkuid')"); 
     280                       if (rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
     281                               $updated++; 
     282                               rss_error('updated schema for table ' . getTable('metatag'), RSS_ERROR_NOTICE); 
     283                       } else { 
     284                               rss_error('Failed updating schema for table ' . getTable('metatag') . ': ' 
     285                                       . rss_sql_error_message(), RSS_ERROR_ERROR); 
     286                       } 
     287                
     288               break; 
    286289    } 
    287290    return $updated; 
     
    459462        "rss.output.usepermalinks"  =>      array("true","true","boolean","Display a permalink icon and allow linking a given item directly.",NULL), 
    460463        "rss.config.markreadonupdate"=> array("false","false","boolean","Mark all old unread feeds as read when updating if new unread feeds are found.",NULL), 
    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), 
    462465        "rss.config.absoluteordering"=> array("true","true","boolean","Allow feeds and folders to be ordered by their order in the admin section. If this option is set to false, channels and folders will be organized alphabetically by their titles.",NULL), 
    463466        "rss.config.robotsmeta"     =>      array("noindex,follow","noindex,follow","string","How should spiders crawl us? (see http://www.robotstxt.org/wc/meta-user.html for more info).",NULL), 
     
    488491        "rss.config.defaultdashboard"           => array('true','true','boolean','If the first page seen when entering the admin section should be the dashboard',NULL), 
    489492        "rss.config.deadthreshhold" =>  array('24', '24', 'num', 'Sets the threshold for when a feed is marked as dead, in hours', NULL), 
    490         "rss.search.maxitems" => array(500, 500, 'num', 'Sets the maximum number of items returned on a search', NULL) 
     493        "rss.search.maxitems" => array(500, 500, 'num', 'Sets the maximum number of items returned on a search', NULL), 
     494        "rss.config.restrictrefresh"    => array("false","false","boolean","Restrict refresh to command line only (eg php -f update.php). Useful for busy sites with multiple users.",NULL), 
    491495    ); 
    492496     
     
    699703} 
    700704 
    701  
    702 /////////////////////////////////////////////////////////////////////////////// 
    703  
     705/////////////////////////////////////////////////////////////////////////////// 
    704706function _init_item2user() { 
    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       } 
    745747} 
    746748 
     
    748750 
    749751function _init_channels2user() { 
    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 
    806809 
    807810function _init_properties() {