Ignore:
Timestamp:
Mar 5, 2014, 9:44:20 PM (10 years ago)
Author:
rvelices
Message:
  • check parent/child album status/visibility/permissions
  • show offending ids for missing foreign keys
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/rv_db_integrity/check_db.php

    r20461 r27563  
    2020  GROUP BY ref.'.$reff;
    2121
    22   $result = pwg_query($query);
    23   return pwg_db_num_rows($result);
     22        return query2array($query,null,$reff);
    2423}
    2524
     
    7574                {
    7675                        $err = check_table_ref($table, $field_name, $test[0], $test[1] );
    77                         if ($err)
     76                        if (count($err))
    7877                        {
    7978                                $failed++;
    80                                 $tpl_var['errors'][]= $err.' error references; #'.$test[0].'.'.$test[1].' referring to #'.$table.'.'.$field_name;
     79                                $tpl_var['errors'][]= count($err).' error references; #'.$test[0].'.'.$test[1].' referring to #'.$table.'.'.$field_name;
     80                                $tpl_var['errors'][]= 'Offending '.$test[1].' '.implode(',',$err);
    8181                        }
    8282                }
     
    107107$template->append('reference_tests', $tpl_var);
    108108
     109// Status/visible tests
     110$tpl_var = array(
     111                'ID' => 'status',
     112                'LABEL' => 'Album status/visibility',
     113                'CHECKED' => isset($_POST['status']) ? 'checked="checked"' : $default_checked,
     114                'COUNT' => 1,
     115        );
     116if (isset($_POST['status']))
     117{
     118        $failed = 0;
     119        $query = '
     120SELECT id,name,id_uppercat,status,visible
     121  FROM '.CATEGORIES_TABLE;
     122        $cats = query2array($query,'id');
     123        foreach($cats as $cat)
     124        {
     125                if (!isset($cat['id_uppercat'])) continue;
     126                if ('public'==$cat['status'] && 'public'!=$cats[$cat['id_uppercat']]['status'])
     127                {
     128                        $failed++;
     129                        $tpl_var['errors'][] = 'Public album '.$cat['id'].' '.$cat['name'].' parent '.$cat['id_uppercat'].' is '.$cats[$cat['id_uppercat']]['status'];
     130                }
     131                if ('true'==$cat['visible'] && 'true'!=$cats[$cat['id_uppercat']]['visible'])
     132                {
     133                        $failed++;
     134                        $tpl_var['errors'][] = 'Visible album '.$cat['id'].' '.$cat['name'].' parent '.$cat['id_uppercat'].' is '.$cats[$cat['id_uppercat']]['visible'];
     135                }
     136        }
     137        $tpl_var['result'] = $failed;
     138}
     139$template->append('reference_tests', $tpl_var);
     140
     141// Permissions
     142$tpl_var = array(
     143                'ID' => 'permissions',
     144                'LABEL' => 'Permissions',
     145                'CHECKED' => isset($_POST['permissions']) ? 'checked="checked"' : $default_checked,
     146                'COUNT' => 1,
     147        );
     148if (isset($_POST['permissions']))
     149{
     150        $query = '
     151SELECT id,name,id_uppercat
     152        FROM '.CATEGORIES_TABLE.'
     153        WHERE status="private"';
     154        $cats = query2array($query,'id');
     155
     156        $groups = array_fill_keys( array_keys($cats), array());
     157        $query = 'SELECT cat_id,group_id FROM '.GROUP_ACCESS_TABLE;
     158        $result = pwg_query($query);
     159        while ($row=pwg_db_fetch_assoc($result))
     160                $groups[$row['cat_id']][] = $row['group_id'];
     161
     162        $users = array_fill_keys( array_keys($cats), array());
     163        $query = 'SELECT cat_id,user_id FROM '.USER_ACCESS_TABLE;
     164        $result = pwg_query($query);
     165        while ($row=pwg_db_fetch_assoc($result))
     166                $users[$row['cat_id']][] = $row['user_id'];
     167
     168        $failed = 0;
     169        foreach($cats as $cat)
     170        {
     171                if (!isset($cats[$cat['id_uppercat']])) continue;
     172                foreach( array('users','groups') as $type)
     173                {
     174                        $arr = $$type;
     175                        $me = $arr[$cat['id']];
     176                        $dad = $arr[$cat['id_uppercat']];
     177                        $delta = array_diff($me, $dad);
     178                        if (count($delta))
     179                        {
     180                                $tpl_var['errors'][] = 'Album '.$cat['id'].' '.$cat['name'].' too many '.$type.' permissions '.implode(',',$delta);
     181                                $failed++;
     182                        }
     183                }
     184        }
     185        $tpl_var['result'] = $failed;
     186}
     187$template->append('reference_tests', $tpl_var);
     188
    109189
    110190// #images(id,storage_category_id) vs. #image_category(image_id,category_id) ---
     
    117197if (isset($_POST['id_storage_category_id']))
    118198{
    119   $query = '
     199        $query = '
    120200SELECT i.id, i.storage_category_id, i.path
    121201  FROM '.IMAGES_TABLE.' i LEFT JOIN '.IMAGE_CATEGORY_TABLE.' ic ON ic.image_id=i.id AND ic.category_id=i.storage_category_id
Note: See TracChangeset for help on using the changeset viewer.