Dotclear

Changeset 1030:ad4942bddbdb for inc/core


Ignore:
Timestamp:
11/19/12 12:34:31 (13 years ago)
Author:
JcDenis
Branch:
default
Message:

Enhance mass posts actions by reducing SQL queries, addresses #943

Location:
inc/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.blog.php

    r1018 r1030  
    12231223     public function updPostStatus($id,$status) 
    12241224     { 
     1225          $this->updPostsStatus($id,$status); 
     1226     } 
     1227      
     1228     /** 
     1229     Updates posts status. 
     1230      
     1231     @param    ids       <b>mixed</b>        Post(s) ID(s) 
     1232     @param    status    <b>integer</b>      Post status 
     1233     */ 
     1234     public function updPostsStatus($ids,$status) 
     1235     { 
    12251236          if (!$this->core->auth->check('publish,contentadmin',$this->id)) { 
    12261237               throw new Exception(__('You are not allowed to change this entry status')); 
    12271238          } 
    12281239           
    1229           $id = (integer) $id; 
     1240          $posts_ids = dcUtils::cleanIds($ids); 
    12301241          $status = (integer) $status; 
     1242           
     1243          $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
     1244                    "AND post_id ".$this->con->in($posts_ids); 
    12311245           
    12321246          #If user can only publish, we need to check the post's owner 
    12331247          if (!$this->core->auth->check('contentadmin',$this->id)) 
    12341248          { 
    1235                $strReq = 'SELECT post_id '. 
    1236                          'FROM '.$this->prefix.'post '. 
    1237                          'WHERE post_id = '.$id.' '. 
    1238                          "AND blog_id = '".$this->con->escape($this->id)."' ". 
    1239                          "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    1240                 
    1241                $rs = $this->con->select($strReq); 
    1242                 
    1243                if ($rs->isEmpty()) { 
    1244                     throw new Exception(__('You are not allowed to change this entry status')); 
    1245                } 
     1249               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    12461250          } 
    12471251           
     
    12511255          $cur->post_upddt = date('Y-m-d H:i:s'); 
    12521256           
    1253           $cur->update( 
    1254                'WHERE post_id = '.$id.' '. 
    1255                "AND blog_id = '".$this->con->escape($this->id)."' " 
    1256                ); 
     1257          $cur->update($strReq); 
    12571258          $this->triggerBlog(); 
    12581259     } 
    12591260      
     1261     /** 
     1262     Updates post selection. 
     1263      
     1264     @param    id        <b>integer</b>      Post ID 
     1265     @param    selected  <b>integer</b>      Is selected post 
     1266     */ 
    12601267     public function updPostSelected($id,$selected) 
     1268     { 
     1269          $this->updPostsSelected($id,$selected); 
     1270     } 
     1271      
     1272     /** 
     1273     Updates posts selection. 
     1274      
     1275     @param    ids       <b>mixed</b>        Post(s) ID(s) 
     1276     @param    selected  <b>integer</b>      Is selected post(s) 
     1277     */ 
     1278     public function updPostsSelected($ids,$selected) 
    12611279     { 
    12621280          if (!$this->core->auth->check('usage,contentadmin',$this->id)) { 
     
    12641282          } 
    12651283           
    1266           $id = (integer) $id; 
     1284          $posts_ids = dcUtils::cleanIds($ids); 
    12671285          $selected = (boolean) $selected; 
     1286           
     1287          $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
     1288                    "AND post_id ".$this->con->in($posts_ids); 
    12681289           
    12691290          # If user is only usage, we need to check the post's owner 
    12701291          if (!$this->core->auth->check('contentadmin',$this->id)) 
    12711292          { 
    1272                $strReq = 'SELECT post_id '. 
    1273                          'FROM '.$this->prefix.'post '. 
    1274                          'WHERE post_id = '.$id.' '. 
    1275                          "AND blog_id = '".$this->con->escape($this->id)."' ". 
    1276                          "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    1277                 
    1278                $rs = $this->con->select($strReq); 
    1279                 
    1280                if ($rs->isEmpty()) { 
    1281                     throw new Exception(__('You are not allowed to mark this entry as selected')); 
    1282                } 
     1293               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    12831294          } 
    12841295           
     
    12881299          $cur->post_upddt = date('Y-m-d H:i:s'); 
    12891300           
    1290           $cur->update( 
    1291                'WHERE post_id = '.$id.' '. 
    1292                "AND blog_id = '".$this->con->escape($this->id)."' " 
    1293           ); 
     1301          $cur->update($strReq); 
    12941302          $this->triggerBlog(); 
    12951303     } 
     
    13031311     public function updPostCategory($id,$cat_id) 
    13041312     { 
     1313          $this->updPostsCategory($id,$cat_id); 
     1314     } 
     1315      
     1316     /** 
     1317     Updates posts category. <var>$cat_id</var> can be null. 
     1318      
     1319     @param    ids       <b>mixed</b>        Post(s) ID(s) 
     1320     @param    cat_id    <b>integer</b>      Category ID 
     1321     */ 
     1322     public function updPostsCategory($ids,$cat_id) 
     1323     { 
    13051324          if (!$this->core->auth->check('usage,contentadmin',$this->id)) { 
    13061325               throw new Exception(__('You are not allowed to change this entry category')); 
    13071326          } 
    13081327           
    1309           $id = (integer) $id; 
     1328          $posts_ids = dcUtils::cleanIds($ids); 
    13101329          $cat_id = (integer) $cat_id; 
     1330           
     1331          $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
     1332                    "AND post_id ".$this->con->in($posts_ids); 
    13111333           
    13121334          # If user is only usage, we need to check the post's owner 
    13131335          if (!$this->core->auth->check('contentadmin',$this->id)) 
    13141336          { 
    1315                $strReq = 'SELECT post_id '. 
    1316                          'FROM '.$this->prefix.'post '. 
    1317                          'WHERE post_id = '.$id.' '. 
    1318                          "AND blog_id = '".$this->con->escape($this->id)."' ". 
    1319                          "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    1320                 
    1321                $rs = $this->con->select($strReq); 
    1322                 
    1323                if ($rs->isEmpty()) { 
    1324                     throw new Exception(__('You are not allowed to change this entry category')); 
    1325                } 
     1337               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    13261338          } 
    13271339           
     
    13311343          $cur->post_upddt = date('Y-m-d H:i:s'); 
    13321344           
    1333           $cur->update( 
    1334                'WHERE post_id = '.$id.' '. 
    1335                "AND blog_id = '".$this->con->escape($this->id)."' " 
    1336           ); 
     1345          $cur->update($strReq); 
    13371346          $this->triggerBlog(); 
    13381347     } 
     
    13441353     @param    new_cat_id     <b>integer</b>      New category ID 
    13451354     */ 
    1346      public function updPostsCategory($old_cat_id,$new_cat_id) 
     1355     public function changePostsCategory($old_cat_id,$new_cat_id) 
    13471356     { 
    13481357          if (!$this->core->auth->check('contentadmin,categories',$this->id)) { 
     
    13721381     public function delPost($id) 
    13731382     { 
     1383          $this->delPosts($id); 
     1384     } 
     1385      
     1386     /** 
     1387     Deletes multiple posts. 
     1388      
     1389     @param    ids       <b>mixed</b>        Post(s) ID(s) 
     1390     */ 
     1391     public function delPosts($ids) 
     1392     { 
    13741393          if (!$this->core->auth->check('delete,contentadmin',$this->id)) { 
    13751394               throw new Exception(__('You are not allowed to delete entries')); 
    13761395          } 
    13771396           
    1378           $id = (integer) $id; 
    1379            
    1380           if (empty($id)) { 
     1397          $posts_ids = dcUtils::cleanIds($ids); 
     1398           
     1399          if (empty($posts_ids)) { 
    13811400               throw new Exception(__('No such entry ID')); 
    13821401          } 
     1402           
     1403          $strReq = 'DELETE FROM '.$this->prefix.'post '. 
     1404                    "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
     1405                    "AND post_id ".$this->con->in($posts_ids); 
    13831406           
    13841407          #If user can only delete, we need to check the post's owner 
    13851408          if (!$this->core->auth->check('contentadmin',$this->id)) 
    13861409          { 
    1387                $strReq = 'SELECT post_id '. 
    1388                          'FROM '.$this->prefix.'post '. 
    1389                          'WHERE post_id = '.$id.' '. 
    1390                          "AND blog_id = '".$this->con->escape($this->id)."' ". 
    1391                          "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    1392                 
    1393                $rs = $this->con->select($strReq); 
    1394                 
    1395                if ($rs->isEmpty()) { 
    1396                     throw new Exception(__('You are not allowed to delete this entry')); 
    1397                } 
    1398           } 
    1399            
    1400            
    1401           $strReq = 'DELETE FROM '.$this->prefix.'post '. 
    1402                     'WHERE post_id = '.$id.' '. 
    1403                     "AND blog_id = '".$this->con->escape($this->id)."' "; 
     1410               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
     1411          } 
    14041412           
    14051413          $this->con->execute($strReq); 
  • inc/core/class.dc.utils.php

    r270 r1030  
    4949          return $user_id; 
    5050     } 
     51      
     52     /** 
     53     Cleanup a list of IDs 
     54      
     55     @param    ids            <b>mixed</b>   ID(s) 
     56     @return   <b>array</b> 
     57     */ 
     58     public static function cleanIds($ids) 
     59     { 
     60          $clean_ids = array(); 
     61           
     62          if (!is_array($ids)) { 
     63               $ids = array($ids); 
     64          } 
     65           
     66          foreach($ids as $id) 
     67          { 
     68               $id = abs((integer) $id); 
     69                
     70               if (!empty($id)) { 
     71                    $clean_ids[] = $id; 
     72               } 
     73          } 
     74          return $clean_ids; 
     75     } 
    5176} 
    5277 
Note: See TracChangeset for help on using the changeset viewer.

Sites map