Main Page | Directories | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages | Examples

t3lib_admin Class Reference

List of all members.

Public Member Functions

 genTree ($theID, $depthData)
 Generates a list of Page-uid's that corresponds to the tables in the tree.
 lostRecords ($pid_list)
 Fills $this->lRecords with the records from all tc-tables that are not attached to a PID in the pid-list.
 fixLostRecord ($table, $uid)
 Fixes lost record from $table with uid $uid by setting the PID to zero.
 countRecords ($pid_list)
 Counts records from $TCA-tables that ARE attached to an existing page.
 getGroupFields ($mode)
 Finding relations in database based on type 'group' (files or database-uid's in a list).
 getFileFields ($uploadfolder)
 Finds all fields that hold filenames from uploadfolder.
 getDBFields ($theSearchTable)
 Returns an array with arrays of table/field pairs which are allowed to hold references to the input table name - according to $TCA.
 selectNonEmptyRecordsWithFkeys ($fkey_arrays)
 This selects non-empty-records from the tables/fields in the fkey_array generated by getGroupFields().
 testFileRefs ()
 Depends on selectNonEmpty....
 testDBRefs ($theArray)
 Depends on selectNonEmpty....
 whereIsRecordReferenced ($searchTable, $id)
 Finding all references to record based on table/uid.
 whereIsFileReferenced ($uploadfolder, $filename)
 Finding all references to file based on uploadfolder / filename.

Public Attributes

 $genTree_includeDeleted = 1
 $perms_clause = ''
 $genTree_makeHTML = 0
 $genTree_idlist = ''
 $getTree_HTML = ''
 $backPath = ''
 $checkFileRefs = Array()
 $checkSelectDBRefs = Array()
 $checkGroupDBRefs = Array()
 $page_idArray = Array()
 $recStat = Array()
 $lRecords = Array()
 $lostPagesList = ''

Member Function Documentation

t3lib_admin::countRecords pid_list  ) 
 

Counts records from $TCA-tables that ARE attached to an existing page.

Parameters:
string list of pid's (page-record uid's). This list is probably made by genTree()
Returns:
array an array with the number of records from all $TCA-tables that are attached to a PID in the pid-list.

Definition at line 208 of file class.t3lib_admin.php.

00208                                     {
00209       global $TCA;
00210       reset($TCA);
00211       $list=Array();
00212       $list_n=Array();
00213       if ($pid_list) {
00214          while (list($table)=each($TCA))  {
00215             t3lib_div::loadTCA($table);
00216             $count = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, 'pid IN ('.$pid_list.')');
00217             if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($count))  {
00218                $list[$table]=$row[0];
00219             }
00220 
00221             $count = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, 'pid IN ('.$pid_list.')'.t3lib_BEfunc::deleteClause($table));
00222             if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($count))  {
00223                $list_n[$table]=$row[0];
00224             }
00225          }
00226       }
00227       return array('all' => $list, 'non_deleted' => $list_n);
00228    }

t3lib_admin::fixLostRecord table,
uid
 

Fixes lost record from $table with uid $uid by setting the PID to zero.

If there is a disabled column for the record that will be set as well.

Parameters:
string Database tablename
integer The uid of the record which will have the PID value set to 0 (zero)
Returns:
boolean True if done.

Definition at line 187 of file class.t3lib_admin.php.

00187                                        {
00188       if ($table && $GLOBALS['TCA'][$table] && $uid && is_array($this->lRecords[$table][$uid]) && $GLOBALS['BE_USER']->user['admin'])  {
00189 
00190          $updateFields = array();
00191          $updateFields['pid'] = 0;
00192          if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']) {  // If possible a lost record restored is hidden as default
00193             $updateFields[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']] = 1;
00194          }
00195 
00196          $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), $updateFields);
00197 
00198          return TRUE;
00199       } else return FALSE;
00200    }

t3lib_admin::genTree theID,
depthData
 

Generates a list of Page-uid's that corresponds to the tables in the tree.

This list should ideally include all records in the pages-table.

Parameters:
integer a pid (page-record id) from which to start making the tree
string HTML-code (image-tags) used when this function calls itself recursively.
Returns:
integer Number of $GLOBALS['TYPO3_DB']->sql_num_rows (most recent query)

Definition at line 116 of file class.t3lib_admin.php.

References $a.

00116                                           {
00117       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00118                'uid,title,doktype,deleted'.(t3lib_extMgm::isLoaded('cms')?',hidden':''),
00119                'pages',
00120                'pid='.intval($theID).' '.((!$this->genTree_includeDeleted)?'AND deleted=0':'').$this->perms_clause,
00121                '',
00122                'sorting'
00123             );
00124       $a=0;
00125       $c = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
00126       while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))  {
00127          $a++;
00128          $newID =$row['uid'];
00129          if ($this->genTree_makeHTML)  {
00130             $this->genTree_HTML.=chr(10).'<div><span class="nobr">';
00131             $PM = 'join';
00132             $LN = ($a==$c)?'blank':'line';
00133             $BTM = ($a==$c)?'bottom':'';
00134             $this->genTree_HTML.= $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' align="top" alt="" />'.t3lib_iconWorks::getIconImage('pages',$row,$this->backPath,'align="top"').htmlspecialchars($row['uid'].': '.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),50)).'</span></div>';
00135          }
00136 
00137          if (isset($page_idlist[$newID])) {
00138             $this->recStat['doublePageID'][]=$newID;
00139          }
00140          $this->page_idArray[$newID]=$newID;
00141          if ($row['deleted']) {$this->recStat['deleted']++;}
00142          if ($row['hidden']) {$this->recStat['hidden']++;}
00143          $this->recStat['doktype'][$row['doktype']]++;
00144 
00145          $this->genTree($newID,$this->genTree_HTML ? $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' align="top" alt="" />'  : '');
00146       }
00147       return $GLOBALS['TYPO3_DB']->sql_num_rows($res);
00148    }

t3lib_admin::getDBFields theSearchTable  ) 
 

Returns an array with arrays of table/field pairs which are allowed to hold references to the input table name - according to $TCA.

Parameters:
string Table name
Returns:
array

Definition at line 293 of file class.t3lib_admin.php.

00293                                           {
00294       global $TCA;
00295       $result = Array();
00296       reset ($TCA);
00297       while (list($table)=each($TCA))  {
00298          t3lib_div::loadTCA($table);
00299          $cols = $TCA[$table]['columns'];
00300          reset ($cols);
00301          while (list($field,$config)=each($cols))  {
00302             if ($config['config']['type']=='group' && $config['config']['internal_type']=='db') {
00303                if (trim($config['config']['allowed'])=='*' || strstr($config['config']['allowed'],$theSearchTable))  {
00304                   $result[]=Array($table,$field);
00305                }
00306             } else if ($config['config']['type']=='select' && $config['config']['foreign_table']==$theSearchTable)   {
00307                $result[]=Array($table,$field);
00308             }
00309          }
00310       }
00311       return $result;
00312    }

t3lib_admin::getFileFields uploadfolder  ) 
 

Finds all fields that hold filenames from uploadfolder.

Parameters:
string Path to uploadfolder
Returns:
array An array with all fields listed that have references to files in the $uploadfolder

Definition at line 270 of file class.t3lib_admin.php.

00270                                           {
00271       global $TCA;
00272       reset ($TCA);
00273       $result = Array();
00274       while (list($table)=each($TCA))  {
00275          t3lib_div::loadTCA($table);
00276          $cols = $TCA[$table]['columns'];
00277          reset ($cols);
00278          while (list($field,$config)=each($cols))  {
00279             if ($config['config']['type']=='group' && $config['config']['internal_type']=='file' && $config['config']['uploadfolder']==$uploadfolder) {
00280                $result[]=Array($table,$field);
00281             }
00282          }
00283       }
00284       return $result;
00285    }

t3lib_admin::getGroupFields mode  ) 
 

Finding relations in database based on type 'group' (files or database-uid's in a list).

Parameters:
string $mode = file, $mode = db, $mode = '' (all...)
Returns:
array An array with all fields listed that somehow are references to other records (foreign-keys) or files

Definition at line 236 of file class.t3lib_admin.php.

00236                                     {
00237       global $TCA;
00238       reset ($TCA);
00239       $result = Array();
00240       while (list($table)=each($TCA))  {
00241          t3lib_div::loadTCA($table);
00242          $cols = $TCA[$table]['columns'];
00243          reset ($cols);
00244          while (list($field,$config)=each($cols))  {
00245             if ($config['config']['type']=='group')   {
00246                if (
00247                   ((!$mode||$mode=='file') && $config['config']['internal_type']=='file') ||
00248                   ((!$mode||$mode=='db') && $config['config']['internal_type']=='db')
00249                   )  {
00250                   $result[$table][]=$field;
00251                }
00252             }
00253             if ( (!$mode||$mode=='db') && $config['config']['type']=='select' && $config['config']['foreign_table']) {
00254                $result[$table][]=$field;
00255             }
00256          }
00257          if ($result[$table]) {
00258             $result[$table] = implode(',',$result[$table]);
00259          }
00260       }
00261       return $result;
00262    }

t3lib_admin::lostRecords pid_list  ) 
 

Fills $this->lRecords with the records from all tc-tables that are not attached to a PID in the pid-list.

Parameters:
string list of pid's (page-record uid's). This list is probably made by genTree()
Returns:
void

Definition at line 156 of file class.t3lib_admin.php.

References table().

00156                                     {
00157       global $TCA;
00158       reset($TCA);
00159       $this->lostPagesList='';
00160       if ($pid_list) {
00161          while (list($table)=each($TCA))  {
00162             t3lib_div::loadTCA($table);
00163             $garbage = $GLOBALS['TYPO3_DB']->exec_SELECTquery (
00164                         'uid,pid,'.$TCA[$table]['ctrl']['label'],
00165                         $table,
00166                         'pid NOT IN ('.$pid_list.')'
00167                      );
00168             $lostIdList=Array();
00169             while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($garbage)) {
00170                $this->lRecords[$table][$row['uid']]=Array('uid'=>$row['uid'], 'pid'=>$row['pid'], 'title'=> strip_tags($row[$TCA[$table]['ctrl']['label']]) );
00171                $lostIdList[]=$row['uid'];
00172             }
00173             if ($table=='pages') {
00174                $this->lostPagesList=implode(',',$lostIdList);
00175             }
00176          }
00177       }
00178    }

t3lib_admin::selectNonEmptyRecordsWithFkeys fkey_arrays  ) 
 

This selects non-empty-records from the tables/fields in the fkey_array generated by getGroupFields().

Parameters:
array Array with tables/fields generated by getGroupFields()
Returns:
void
See also:
getGroupFields()

Definition at line 321 of file class.t3lib_admin.php.

00321                                                          {
00322       global $TCA;
00323       if (is_array($fkey_arrays))   {
00324          reset($fkey_arrays);
00325          while (list($table,$field_list)=each($fkey_arrays))   {
00326             if ($TCA[$table] && trim($field_list)) {
00327                t3lib_div::loadTCA($table);
00328                $fieldArr = explode(',',$field_list);
00329                $cl_fl = implode ('!="" OR ',$fieldArr). '!=""';
00330                $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,'.$field_list, $table, $cl_fl);
00331                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
00332                   reset($fieldArr);
00333                   while (list(,$field)=each($fieldArr))  {
00334                      if (trim($row[$field]))    {
00335                         $fieldConf = $TCA[$table]['columns'][$field]['config'];
00336                         if ($fieldConf['type']=='group') {
00337                            if ($fieldConf['internal_type']=='file')  {
00338                               // files...
00339                               if ($fieldConf['MM'])   {
00340                                  $tempArr=array();
00341                                  $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
00342                                  $dbAnalysis->start('','files',$fieldConf['MM'],$row['uid']);
00343                                  reset($dbAnalysis->itemArray);
00344                                  while (list($somekey,$someval)=each($dbAnalysis->itemArray))   {
00345                                     if ($someval['id'])  {
00346                                        $tempArr[]=$someval['id'];
00347                                     }
00348                                  }
00349                               } else {
00350                                  $tempArr = explode(',',trim($row[$field]));
00351                               }
00352                               reset($tempArr);
00353                               while (list(,$file)=each($tempArr)) {
00354                                  $file = trim($file);
00355                                  if ($file)  {
00356                                     $this->checkFileRefs[$fieldConf['uploadfolder']][$file]+=1;
00357                                  }
00358                               }
00359                            }
00360                            if ($fieldConf['internal_type']=='db') {
00361                               // dbs - group
00362                               $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
00363                               $dbAnalysis->start($row[$field],$fieldConf['allowed'],$fieldConf['MM'],$row['uid']);
00364                               reset($dbAnalysis->itemArray);
00365                               while (list(,$tempArr)=each($dbAnalysis->itemArray))  {
00366                                  $this->checkGroupDBRefs[$tempArr['table']][$tempArr['id']]+=1;
00367                               }
00368                            }
00369                         }
00370                         if ($fieldConf['type']=='select' && $fieldConf['foreign_table'])  {
00371                            // dbs - select
00372                            $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
00373                            $dbAnalysis->start($row[$field],$fieldConf['foreign_table'],$fieldConf['MM'],$row['uid']);
00374                            reset($dbAnalysis->itemArray);
00375                            while (list(,$tempArr)=each($dbAnalysis->itemArray))  {
00376                               if ($tempArr['id']>0)   {
00377                                  $this->checkGroupDBRefs[$fieldConf['foreign_table']][$tempArr['id']]+=1;
00378                               }
00379                            }
00380                         }
00381                      }
00382                   }
00383                }
00384             }
00385          }
00386       }
00387    }

t3lib_admin::testDBRefs theArray  ) 
 

Depends on selectNonEmpty....

to be executed first!!

Parameters:
array Table with key/value pairs being table names and arrays with uid numbers
Returns:
string HTML Error message

Definition at line 445 of file class.t3lib_admin.php.

References $TCA, and table().

00445                                     {
00446       global $TCA;
00447       reset($theArray);
00448       while(list($table,$dbArr)=each($theArray))   {
00449          if ($TCA[$table]) {
00450             $idlist = Array();
00451             while(list($id,)=each($dbArr))   {
00452                $idlist[]=$id;
00453             }
00454             $theList = implode(',',$idlist);
00455             if ($theList)  {
00456                $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'uid IN ('.$theList.')'.t3lib_BEfunc::deleteClause($table));
00457                while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres))  {
00458                   if (isset($dbArr[$row['uid']]))  {
00459                      unset ($dbArr[$row['uid']]);
00460                   } else {
00461                      $result.='Strange Error. ...<br />';
00462                   }
00463                }
00464                reset($dbArr);
00465                while (list($theId,$theC)=each($dbArr))   {
00466                   $result.='There are '.$theC.' records pointing to this missing or deleted record; ['.$table.']['.$theId.']<br />';
00467                }
00468             }
00469          } else {
00470             $result.='Codeerror. Table is not a table...<br />';
00471          }
00472       }
00473       return $result;
00474    }

t3lib_admin::testFileRefs  ) 
 

Depends on selectNonEmpty....

to be executed first!!

Returns:
array Report over files; keys are "moreReferences", "noReferences", "noFile", "error"

Definition at line 394 of file class.t3lib_admin.php.

References error(), PATH_site, and table().

00394                               {
00395       $output=Array();
00396       reset($this->checkFileRefs);
00397       while(list($folder,$fileArr)=each($this->checkFileRefs)) {
00398          $path = PATH_site.$folder;
00399          if (@is_dir($path))  {
00400             $d = dir($path);
00401             while($entry=$d->read()) {
00402                if (@is_file($path.'/'.$entry))  {
00403                   if (isset($fileArr[$entry]))  {
00404                      if ($fileArr[$entry] > 1)  {
00405                         $temp = $this->whereIsFileReferenced($folder,$entry);
00406                         $tempList = '';
00407                         while(list(,$inf)=each($temp))   {
00408                            $tempList.='['.$inf['table'].']['.$inf['uid'].']['.$inf['field'].'] (pid:'.$inf['pid'].') - ';
00409                         }
00410                         $output['moreReferences'][] = Array($path,$entry,$fileArr[$entry],$tempList);
00411                      }
00412                      unset($fileArr[$entry]);
00413                   } else {
00414                      if (!strstr($entry,'index.htm')) {
00415                         $output['noReferences'][] = Array($path,$entry);
00416                      }
00417                   }
00418                }
00419             }
00420             $d->close();
00421             reset($fileArr);
00422             $tempCounter=0;
00423             while(list($file,)=each($fileArr))  {
00424                $temp = $this->whereIsFileReferenced($folder,$file);
00425                $tempList = '';
00426                while(list(,$inf)=each($temp))   {
00427                   $tempList.='['.$inf['table'].']['.$inf['uid'].']['.$inf['field'].'] (pid:'.$inf['pid'].') - ';
00428                }
00429                $tempCounter++;
00430                $output['noFile'][substr($path,-3).'_'.substr($file,0,3).'_'.$tempCounter] = Array($path,$file,$tempList);
00431             }
00432          } else {
00433             $output['error'][] = Array($path);
00434          }
00435       }
00436       return $output;
00437    }

t3lib_admin::whereIsFileReferenced uploadfolder,
filename
 

Finding all references to file based on uploadfolder / filename.

Parameters:
string Upload folder where file is found
string Filename to search for
Returns:
array Array with other arrays containing information about where references was found

Definition at line 520 of file class.t3lib_admin.php.

References table().

00520                                                             {
00521       global $TCA;
00522       $fileFields = $this->getFileFields($uploadfolder); // Gets tables / Fields that reference to files...
00523       $theRecordList=Array();
00524       while (list(,$info)=each($fileFields)) {
00525          $table=$info[0];  $field=$info[1];
00526          $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00527                      'uid,pid,'.$TCA[$table]['ctrl']['label'].','.$field,
00528                      $table,
00529                      $field.' LIKE "%'.$GLOBALS['TYPO3_DB']->quoteStr($filename, $table).'%"'
00530                   );
00531          while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
00532             // Now this is the field, where the reference COULD come from. But we're not garanteed, so we must carefully examine the data.
00533             $tempArr = explode(',',trim($row[$field]));
00534             while (list(,$file)=each($tempArr)) {
00535                $file = trim($file);
00536                if ($file==$filename)   {
00537                   $theRecordList[]=Array('table'=>$table,'uid'=>$row['uid'],'field'=>$field,'pid'=>$row['pid']);
00538                }
00539             }
00540          }
00541       }
00542       return $theRecordList;
00543    }

t3lib_admin::whereIsRecordReferenced searchTable,
id
 

Finding all references to record based on table/uid.

Parameters:
string Table name
integer Uid of database record
Returns:
array Array with other arrays containing information about where references was found

Definition at line 483 of file class.t3lib_admin.php.

References $TCA, and table().

00483                                                       {
00484       global $TCA;
00485       $fileFields = $this->getDBFields($searchTable); // Gets tables / Fields that reference to files...
00486       $theRecordList=Array();
00487       while (list(,$info)=each($fileFields)) {
00488          $table=$info[0];  $field=$info[1];
00489          t3lib_div::loadTCA($table);
00490          $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00491                      'uid,pid,'.$TCA[$table]['ctrl']['label'].','.$field,
00492                      $table,
00493                      $field.' LIKE "%'.$GLOBALS['TYPO3_DB']->quoteStr($id, $table).'%"'
00494                   );
00495          while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
00496                // Now this is the field, where the reference COULD come from. But we're not garanteed, so we must carefully examine the data.
00497             $fieldConf = $TCA[$table]['columns'][$field]['config'];
00498             $allowedTables = ($fieldConf['type']=='group') ? $fieldConf['allowed'] : $fieldConf['foreign_table'];
00499 
00500             $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
00501             $dbAnalysis->start($row[$field],$allowedTables,$fieldConf['MM'],$row['uid']);
00502             reset($dbAnalysis->itemArray);
00503             while (list(,$tempArr)=each($dbAnalysis->itemArray))  {
00504                if ($tempArr['table']==$searchTable && $tempArr['id']==$id) {
00505                   $theRecordList[]=Array('table'=>$table,'uid'=>$row['uid'],'field'=>$field,'pid'=>$row['pid']);
00506                }
00507             }
00508          }
00509       }
00510       return $theRecordList;
00511    }


Member Data Documentation

t3lib_admin::$backPath = ''
 

Definition at line 97 of file class.t3lib_admin.php.

t3lib_admin::$checkFileRefs = Array()
 

Definition at line 100 of file class.t3lib_admin.php.

t3lib_admin::$checkGroupDBRefs = Array()
 

Definition at line 102 of file class.t3lib_admin.php.

t3lib_admin::$checkSelectDBRefs = Array()
 

Definition at line 101 of file class.t3lib_admin.php.

t3lib_admin::$genTree_idlist = ''
 

Definition at line 95 of file class.t3lib_admin.php.

t3lib_admin::$genTree_includeDeleted = 1
 

Definition at line 91 of file class.t3lib_admin.php.

t3lib_admin::$genTree_makeHTML = 0
 

Definition at line 93 of file class.t3lib_admin.php.

t3lib_admin::$getTree_HTML = ''
 

Definition at line 96 of file class.t3lib_admin.php.

t3lib_admin::$lostPagesList = ''
 

Definition at line 107 of file class.t3lib_admin.php.

t3lib_admin::$lRecords = Array()
 

Definition at line 106 of file class.t3lib_admin.php.

t3lib_admin::$page_idArray = Array()
 

Definition at line 104 of file class.t3lib_admin.php.

t3lib_admin::$perms_clause = ''
 

Definition at line 92 of file class.t3lib_admin.php.

t3lib_admin::$recStat = Array()
 

Definition at line 105 of file class.t3lib_admin.php.


The documentation for this class was generated from the following file:
Generated on Sun Oct 3 01:06:36 2004 for TYPO3core 3.7.0 dev by  doxygen 1.3.8-20040913