| 1 |
<?php
|
| 2 |
// $Id: auditfiles.module,v 1.5 2007/12/05 22:33:19 stuartgreenfield Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Audit files carries out a simple audit of the Drupal upload directory
|
| 6 |
* and the {files} table, to look for inconsistencies
|
| 7 |
*/
|
| 8 |
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_help().
|
| 12 |
*/
|
| 13 |
function auditfiles_help($path, $arg) {
|
| 14 |
switch ($path) {
|
| 15 |
case 'admin/settings/auditfiles':
|
| 16 |
return t('You can choose to exclude specific files, paths and extensions from the \'files
|
| 17 |
not in database\' audit report by adding them to the relevant lists below.');
|
| 18 |
case 'admin/help#auditfiles':
|
| 19 |
return '<p>'. t('The audit files module performs an audit of the file table and the files
|
| 20 |
directory to check for inconsistencies.') .'</p>';
|
| 21 |
case 'admin/reports/auditfiles':
|
| 22 |
$output .= '<p>'.t('The files listed below are in the files directory on the server but
|
| 23 |
appear to have no corresponding entry in the {files} table. Files in "temporary" folders
|
| 24 |
such as those created by the image module are included in order to check that they are not
|
| 25 |
filling up. You can choose to delete files from this report but remember that if you do
|
| 26 |
this the action cannot be undone. You can also add files to the {files} table - you might
|
| 27 |
do this if you have uploaded files outside of Drupal (e.g., by ftp) and will be attaching
|
| 28 |
them to nodes through the other tools.').'</p>';
|
| 29 |
$output .= '<p>'.t('Files in this list are relative to the files directory %directorypath.', array('%directorypath' => file_directory_path())).'</p>';
|
| 30 |
// If on a confirmation form then suppress the help message
|
| 31 |
if ($_POST['operation'] && $_POST['files']) $output = '';
|
| 32 |
return $output;
|
| 33 |
case 'admin/reports/auditfiles/notonserver':
|
| 34 |
$output .= '<p>'.t('The files listed below are in the {files} table but the physical files
|
| 35 |
do not exist on the server. This might mean the file has been deleted using a program such
|
| 36 |
as FTP, or it may mean there is an error in the database.</p><p>If the file was uploaded
|
| 37 |
using the upload module then you can click on the node number to view the item to which
|
| 38 |
the missing file relates to try and determine what action needs to be taken, or you can
|
| 39 |
click the edit link to open the node editing form directly.').'</p>';
|
| 40 |
$output .= '<p>'.t('Files in this list are relative to the files directory %directorypath.',
|
| 41 |
array('%directorypath' => file_directory_path())).'</p>';
|
| 42 |
return $output;
|
| 43 |
case 'admin/reports/auditfiles/references':
|
| 44 |
$output .= '<p>'.t('Listed here are file references embedded in node bodies which do
|
| 45 |
not have exact correspondences in the {files} and {upload} tables. If there is a file
|
| 46 |
in the {files} table with a corresponding base name, that is listed. Scenarios are:
|
| 47 |
<ul><li><strong>No match at all in the {files} table.</strong> Go to <strong>Files
|
| 48 |
not in database</strong> and make sure any files that exist have been added to the database.
|
| 49 |
If they have, you should either find and upload the missing file and run this report
|
| 50 |
again, or remove the reference from the node.</li>
|
| 51 |
<li><strong>Multiple matches in the {files} table.</strong> This can happen when the same
|
| 52 |
filename is in multiple directories in the uploded file hierarchy. You can review the
|
| 53 |
alternate files and delete any that are true duplicates. When different files have the
|
| 54 |
same basename, you can select the one that goes with the given node and choose
|
| 55 |
<strong>Attach selected files</strong>. This will rewrite the reference in the node
|
| 56 |
to use the canonical relative URL to the file, and if necessary add the reference
|
| 57 |
to the {upload} table.</li>
|
| 58 |
<li><strong>A single match in the {files} table.</strong> You can make the attachments
|
| 59 |
between these nodes and the corresponding files one-by-one by selecting them and choosing
|
| 60 |
<strong>Attach selected files</strong>, or automatically apply it to all single-match
|
| 61 |
cases with <strong>Attach all unique matches</strong>.</li></ul>').'</p>';
|
| 62 |
$output .= '<p>'.t('Files in this list are relative to the files directory %directorypath.',
|
| 63 |
array('%directorypath' => file_directory_path())).'</p>';
|
| 64 |
return $output;
|
| 65 |
case 'admin/reports/auditfiles/unreferenced':
|
| 66 |
$output .= '<p>'.t('The files listed below are in the {files} table but no nodes are recorded
|
| 67 |
as referencing them (i.e., there\'s no entry in the {upload} table). This might mean the
|
| 68 |
node has been deleted without deleting the file, or that the files were uploaded by some
|
| 69 |
means other than the upload module (e.g., ftp) and the relationships between files and
|
| 70 |
nodes have not been made. If you have used the <strong>Missing references</strong> report
|
| 71 |
and accounted for all files that should be referenced, and are sure that the files below
|
| 72 |
are not needed, you can delete them. Click on the basename to get a list of all nodes
|
| 73 |
referencing that base filename (the <strong>Missing references</strong> report only
|
| 74 |
identifies <strong><img></strong> and <strong>window.open</strong> references,
|
| 75 |
this may help you identify if the file is referenced by another means).').'</p>';
|
| 76 |
$output .= '<p>'.t('Files in this list are relative to the files directory %directorypath.',
|
| 77 |
array('%directorypath' => file_directory_path())).'</p>';
|
| 78 |
return $output;
|
| 79 |
}
|
| 80 |
}
|
| 81 |
|
| 82 |
|
| 83 |
/**
|
| 84 |
* Implementation of hook_perm().
|
| 85 |
*/
|
| 86 |
function auditfiles_perm() {
|
| 87 |
return array(
|
| 88 |
'access file audits',
|
| 89 |
'administer file audits',
|
| 90 |
);
|
| 91 |
}
|
| 92 |
|
| 93 |
|
| 94 |
/**
|
| 95 |
* Implementation of hook_menu().
|
| 96 |
*/
|
| 97 |
function auditfiles_menu() {
|
| 98 |
|
| 99 |
$items = array();
|
| 100 |
|
| 101 |
$items['admin/reports/auditfiles'] = array(
|
| 102 |
'title' => t('Audit files'),
|
| 103 |
'description' => t('List files that are not on the server or not in the database.'),
|
| 104 |
'page callback' => 'auditfiles_notindb',
|
| 105 |
'access arguments' => array('access file audits'),
|
| 106 |
'file' => 'notindb.admin.inc',
|
| 107 |
);
|
| 108 |
|
| 109 |
$items['admin/reports/auditfiles/notindb'] = array(
|
| 110 |
'title' => t('Not in database'),
|
| 111 |
'description' => t('List files that are on the server but are not in the database.'),
|
| 112 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 113 |
'weight' => -10,
|
| 114 |
);
|
| 115 |
|
| 116 |
$items['admin/reports/auditfiles/notonserver'] = array(
|
| 117 |
'title' => t('Not on server'),
|
| 118 |
'description' => t('List files that are in the database, but are not on the server.'),
|
| 119 |
'page callback' => 'auditfiles_notonserver',
|
| 120 |
'access arguments' => array('access file audits'),
|
| 121 |
'type' => MENU_LOCAL_TASK,
|
| 122 |
'file' => 'notonserver.admin.inc',
|
| 123 |
'weight' => -5,
|
| 124 |
);
|
| 125 |
|
| 126 |
$items['admin/reports/auditfiles/references'] = array(
|
| 127 |
'title' => t('Missing references'),
|
| 128 |
'description' => t('List files referenced by nodes, but not properly linked or attached.'),
|
| 129 |
'page callback' => 'auditfiles_references',
|
| 130 |
'access arguments' => array('access file audits'),
|
| 131 |
'type' => MENU_LOCAL_TASK,
|
| 132 |
'file' => 'references.admin.inc',
|
| 133 |
'weight' => 0,
|
| 134 |
);
|
| 135 |
|
| 136 |
$items['admin/reports/auditfiles/unreferenced'] = array(
|
| 137 |
'title' => t('Unreferenced'),
|
| 138 |
'description' => t('List files that are in the database, but are not referenced by any node.'),
|
| 139 |
'page callback' => 'auditfiles_unreferenced',
|
| 140 |
'access arguments' => array('access file audits'),
|
| 141 |
'type' => MENU_LOCAL_TASK,
|
| 142 |
'file' => 'unreferenced.admin.inc',
|
| 143 |
'weight' => 5,
|
| 144 |
);
|
| 145 |
|
| 146 |
$items['admin/reports/auditfiles/unreferenced/%'] = array(
|
| 147 |
'title' => 'Referencing nodes',
|
| 148 |
'page callback' => 'drupal_get_form',
|
| 149 |
'page arguments' => array('auditfiles_node_references_form', 4),
|
| 150 |
'access arguments' => array('access file audits'),
|
| 151 |
'type' => MENU_CALLBACK,
|
| 152 |
'file' => 'unreferenced.admin.inc',
|
| 153 |
);
|
| 154 |
|
| 155 |
$items['admin/settings/auditfiles'] = array(
|
| 156 |
'title' => 'Audit files',
|
| 157 |
'description' => 'Set file, extension and path exclusions for file audits.',
|
| 158 |
'page callback' => 'drupal_get_form',
|
| 159 |
'page arguments' => array('auditfiles_admin_settings'),
|
| 160 |
'access arguments' => array('administer file audits'),
|
| 161 |
'file' => 'auditfiles.admin.inc',
|
| 162 |
);
|
| 163 |
|
| 164 |
return $items;
|
| 165 |
}
|
| 166 |
|
| 167 |
|
| 168 |
/**
|
| 169 |
* Implementation of hook_theme()
|
| 170 |
*/
|
| 171 |
function auditfiles_theme() {
|
| 172 |
return array(
|
| 173 |
'auditfiles_notindb_form' => array(
|
| 174 |
'arguments' => array('form' => NULL),
|
| 175 |
'file' => 'notindb.admin.inc',
|
| 176 |
),
|
| 177 |
'auditfiles_unreferenced_form' => array(
|
| 178 |
'arguments' => array('form' => NULL),
|
| 179 |
'file' => 'unreferenced.admin.inc',
|
| 180 |
),
|
| 181 |
'auditfiles_node_references_form' => array(
|
| 182 |
'arguments' => array('form' => NULL),
|
| 183 |
'file' => 'unreferenced.admin.inc',
|
| 184 |
),
|
| 185 |
'auditfiles_references_form' => array(
|
| 186 |
'arguments' => array('form' => NULL),
|
| 187 |
'file' => 'references.admin.inc',
|
| 188 |
),
|
| 189 |
);
|
| 190 |
}
|