Ticket #189: console-update.2.diff

File console-update.2.diff, 4.8 kB (added by Darth_Sebulba05@…, 3 years ago)

Modified populate to take an optional array of IDs and use it in the ConsoleUpdate? render().

  • cls/update.php

     
    5555        var $chans = array (); 
    5656 
    5757        function Update() { 
    58  
    5958                $this->populate(); 
    6059                 
    6160                // Script timeout: ten seconds per feed should be a good upper limit 
     
    6463        } 
    6564 
    6665        function populate() { 
     66                $argc = func_num_args(); 
     67 
    6768                $sql = "select c.id, c.url, c.title from ".getTable("channels") . " c, " 
    68                 . getTable('folders') . " f "; 
    69                 $sql .= " where not(c.mode & ".FEED_MODE_DELETED_STATE.") "; 
     69                . getTable('folders') . " f where "; 
     70 
     71                if(1 == $argc) { 
     72                        $argv = func_get_arg(0); 
     73                        $num = count($argv); 
     74                        if($num > 0) { 
     75                                for($i = 0; $i < $num; $i++) { 
     76                                        print($i); 
     77                                        $id = $argv[$i]; 
     78 
     79                                        if(0 == $i) { 
     80                                                $sql .= " ("; 
     81                                        } 
     82 
     83                                        $sql .= " c.id=" . $id . " "; 
     84 
     85                                        if($i == ($num-1)) { 
     86                                                $sql .= ") and "; 
     87                                        } else { 
     88                                                $sql .= " or "; 
     89                                        } 
     90                                } 
     91                        } 
     92                } 
     93                         
     94                $sql .= " not(c.mode & ".FEED_MODE_DELETED_STATE.") "; 
    7095                $sql .= " and c.parent = f.id "; 
    7196                 
    7297                if (hidePrivate()) { 
    7398                        $sql .= " and not(mode & ".FEED_MODE_PRIVATE_STATE.") "; 
    7499                } 
    75  
     100                 
    76101                if (getConfig('rss.config.absoluteordering')) { 
    77102                        $sql .= " order by f.position asc, c.position asc"; 
    78103                } else { 
    79104                        $sql .= " order by f.name, c.title asc"; 
    80105                } 
    81                  
     106 
    82107                $res = rss_query($sql); 
    83108                while (list ($cid, $url, $title) = rss_fetch_row($res)) { 
    84109                        $this->chans[] = array ($cid, $url, $title); 
    85110                } 
    86111        } 
    87112 
     113        /** Translates a magpie error code into a local error type 
     114                *       and label. 
     115                *       @param $error, the error to translate. 
     116                * @return An array containing the error label and the local 
     117                *               error. 
     118                */ 
     119        function translateError($error) { 
     120                if ($error & MAGPIE_FEED_ORIGIN_CACHE) { 
     121                        if ($error & MAGPIE_FEED_ORIGIN_HTTP_304) { 
     122                                $label = LBL_UPDATE_NOT_MODIFIED; 
     123                                $cls = ERROR_NOERROR; 
     124                        } 
     125                        elseif ($error & MAGPIE_FEED_ORIGIN_HTTP_TIMEOUT) { 
     126                                $label = LBL_UPDATE_CACHE_TIMEOUT; 
     127                                $cls = ERROR_WARNING; 
     128                        } 
     129                        elseif ($error & MAGPIE_FEED_ORIGIN_NOT_FETCHED) { 
     130                                $label = LBL_UPDATE_STATUS_CACHED; 
     131                                $cls = ERROR_NOERROR; 
     132                        } 
     133                        elseif ($error & MAGPIE_FEED_ORIGIN_HTTP_404) { 
     134                                $label = LBL_UPDATE_NOT_FOUND; 
     135                                $cls = ERROR_ERROR; 
     136                        } else { 
     137                                $label = $error; 
     138                                $cls = ERROR_ERROR; 
     139                        } 
     140                } 
     141                elseif ($error & MAGPIE_FEED_ORIGIN_HTTP_200) { 
     142                        $label = LBL_UPDATE_STATUS_OK; 
     143                        $cls = ERROR_NOERROR; 
     144                } else { 
     145                        if (is_numeric($error)) { 
     146                                $label = LBL_UPDATE_STATUS_ERROR; 
     147                                $cls = ERROR_ERROR; 
     148                        } else { 
     149                                // shoud contain MagpieError at this point 
     150                                $label = $error; 
     151                                $cls = ERROR_ERROR; 
     152                        } 
     153                } 
     154 
     155                return array('label' => $label, 'error' => $cls); 
     156        } 
     157 
    88158        function cleanUp($newIds) { 
    89159                if (count($newIds) > 0 && getConfig('rss.config.markreadonupdate')) { 
    90160                        rss_query("update ".getTable("item")." set unread = unread & ".SET_MODE_READ_STATE." where unread & ".FEED_MODE_UNREAD_STATE." and id not in (".implode(",", $newIds).")"); 
     
    137207                        } 
    138208                        $unread = count($unreadIds); 
    139209 
    140                         if ($error & MAGPIE_FEED_ORIGIN_CACHE) { 
    141                                 if ($error & MAGPIE_FEED_ORIGIN_HTTP_304) { 
    142                                         $label = LBL_UPDATE_NOT_MODIFIED; 
    143                                         $cls = ERROR_NOERROR; 
    144                                 } 
    145                                 elseif ($error & MAGPIE_FEED_ORIGIN_HTTP_TIMEOUT) { 
    146                                         $label = LBL_UPDATE_CACHE_TIMEOUT; 
    147                                         $cls = ERROR_WARNING; 
    148                                 } 
    149                                 elseif ($error & MAGPIE_FEED_ORIGIN_NOT_FETCHED) { 
    150                                         $label = LBL_UPDATE_STATUS_CACHED; 
    151                                         $cls = ERROR_NOERROR; 
    152                                 } 
    153                                 elseif ($error & MAGPIE_FEED_ORIGIN_HTTP_404) { 
    154                                         $label = LBL_UPDATE_NOT_FOUND; 
    155                                         $cls = ERROR_ERROR; 
    156                                 } else { 
    157                                         $label = $error; 
    158                                         $cls = ERROR_ERROR; 
    159                                 } 
    160                         } 
    161                         elseif ($error & MAGPIE_FEED_ORIGIN_HTTP_200) { 
    162                                 $label = LBL_UPDATE_STATUS_OK; 
    163                                 $cls = ERROR_NOERROR; 
    164                         } else { 
    165                                 if (is_numeric($error)) { 
    166                                         $label = LBL_UPDATE_STATUS_ERROR; 
    167                                         $cls = ERROR_ERROR; 
    168                                 } else { 
    169                                         // shoud contain MagpieError at this point 
    170                                         $label = $error; 
    171                                         $cls = ERROR_ERROR; 
    172                                 } 
    173                         } 
     210                        $tmp            = parent::translateError($error); 
     211                        $label  = $tmp['label']; 
     212                        $cls            = $tmp['error']; 
    174213                         
    175214                        if ($cls == ERROR_ERROR && !defined("UPDATE_ERROR")) { 
    176215                                define("UPDATE_ERROR", true); 
     
    261300        } 
    262301} 
    263302 
     303class ConsoleUpdate extends Update { 
     304        function ConsoleUpdate() { 
     305        } 
     306 
     307        function render() { 
     308                parent::populate(func_get_args()); 
     309 
     310                foreach($this->chans as $chan) { 
     311                        list ($cid, $url, $title) = $chan; 
     312 
     313                        $ret = update($cid); 
     314 
     315                        $tmp = parent::translateError($ret[0]); 
     316 
     317                        if(defined('CONSOLE_OUTPUT') && 1 == CONSOLE_OUTPUT) { 
     318                                echo $title . "\t" . $tmp['label'] . "\t" . count($ret[1]) . "\n"; 
     319                        } 
     320       
     321                        if (!hidePrivate()) { 
     322                        parent::cleanUp($ret[1]); 
     323                        } 
     324                } 
     325        } 
     326} 
     327 
    264328function pushHeaderCallBack() { 
    265329        echo "WARNING: YOUR BROWSER DOESN'T SUPPORT THIS SERVER-PUSH TECHNOLOGY."; 
    266330        echo "\n".PUSH_BOUNDARY."\n";