%META:TOPICINFO{author="TWikiContributor" date="1305441172" format="1.1" version="$Rev$"}%
---+!! !UpdateAttachmentsPlugin
<!--
   Contributions to this plugin are appreciated. Please update the plugin page at
   http://twiki.org/cgi-bin/view/Plugins/UpdateAttachmentsPlugin or provide feedback at
   http://twiki.org/cgi-bin/view/Plugins/UpdateAttachmentsPluginDev.
   If you are a TWiki contributor please update the plugin in the SVN repository.

   * Set SHORTDESCRIPTION = Add and remove attachments in batch mode
-->
<sticky><div style="float:right; background-color:#EBEEF0; margin:0 0 20px 20px; padding: 0 10px 0 10px;">
%TOC{title="Page contents"}%
</div></sticky>
%SHORTDESCRIPTION%

---++ Usage

This plugin provides a rest handler that can replace the inbuilt ={AutoAttachPubFiles}= functionality with a batched update - so you can upload (ftp, drag&drop etc) thousands of images into TWiki's pub area, and then tell TWiki to update the attachments to all your topics.

This will allow you to SEARCH for attachments, use TWiki:Plugins/DBCacheContrib & TWiki:Plugins/DBCachePlugin, and use any other functionality that relies on the topic files containing references to the attachments.

Doing this may provide a speed advantage as it will remove the need for TWiki to scan the requested topics' attachment directory.

Also, it will (optionally) remove attachment references to files that no longer exist in the topic's attachment directory.

Warning: because TWiki does not deal well with attachments with special characters (or even spaces) in them, these files will be ignored on update.

Warning: checking 28500 topics (many with attachments) takes around 2-3 minutes on my test system, with no plugins that have an beforeSave or afterSave handler registered.

---+++ Triggering an Attachment Update

As this is a [[%SYSTEMWEB%.TWikiScripts#rest][REST handler]] based plugin, you can trigger it to run from a suitably authenticated URL (it will only update topics your user as permission to edit) - for example, to update the Sandbox web
   * =%SCRIPTURL{rest}%/UpdateAttachmentsPlugin/update?topic=Sandbox.WebHome=

Or using a cronjob - make sure the cronjob is running as the same user as TWiki's web access is
   * =./rest <nop>UpdateAttachmentsPlugin.update topic <nop>Sandbox.WebHome=
   
__Note:__ If you get a 500 or premature end of script error, chances are your current user does not have permission to change the web or topics.

---++ Settings

These settings are in the configure web interface in the <nop>Update Attachments Plugin section of [[%SCRIPTURL{configure}%][configure]].
   * =$TWiki::cfg{Plugins}{UpdateAttachmentsPlugin}{AttachAsUser}= - defaults to the unknown user. To reset the attributed user for attachments that already exist, =touch= the files in the attachment directory.
   * =$TWiki::cfg{Plugins}{UpdateAttachmentsPlugin}{RemoveMissing}= - will remove attachment references in a topic that no longer exist
   * =$TWiki::cfg{Plugins}{UpdateAttachmentsPlugin}{UseDangerousNoHandlersSave}= - use with extreme caution, _if_ you understand what the results of a no_handler save are, and _if_ you are able to recover your TWiki if it fails.
   * =$TWiki::cfg{Plugins}{UpdateAttachmentsPlugin}{Debug}= - to see what topics are updated (edit !LocalSite.cfg by hand to add this setting).

It is recommended to disable $TWiki::cfg{AutoAttachPubFiles}.

---++ Installation Instructions

This plugin _may_ not function correctly if =$TWiki::cfg{AutoAttachPubFiles}= is on, predominantly on the WebHome and WebPreferences topics.

You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server where TWiki is running.

Like many other TWiki extensions, this module is shipped with a fully
automatic installer script written using the Build<nop>Contrib.
   * If you have TWiki 4.2 or later, you can install from the =configure= interface (Go to Plugins->Find More Extensions)
      * See the [[http://twiki.org/cgi-bin/view/Plugins/BuildContribInstallationSupplement][installation supplement]] on TWiki.org for more information.
   * If you have any problems, then you can still install manually from the command-line:
      1 Download one of the =.zip= or =.tgz= archives
      1 Unpack the archive in the root directory of your TWiki installation.
      1 Run the installer script ( =perl &lt;module&gt;_installer= )
      1 Run =configure= and enable the module, if it is a plugin.
      1 Repeat for any missing dependencies.
   * If you are *still* having problems, then instead of running the installer script:
      1 Make sure that the file permissions allow the webserver user to access all files.
      1 Check in any installed files that have existing =,v= files in your existing install (take care *not* to lock the files when you check in)
      1 Manually edit !LocalSite.cfg to set any configuration variables.

%IF{"defined 'SYSTEMWEB'" else="<div class='twikiAlert'>%X% WARNING: SYSTEMWEB is not defined in this TWiki. Please add these definitions to your %MAINWEB%.TWikiPreferences, if they are not already there:<br><pre>   * <nop>Set SYSTEMWEB = %<nop>TWIKIWEB%<br>   * <nop>Set USERSWEB = %<nop>MAINWEB%</pre></div>"}%


---++ Plugin Info

|  Plugin Author: | TWiki:Main.SvenDowideit - http://distributedINFORMATION.com |
|  Copyright: | &copy; 2007 SvenDowideit@distributedINFORMATION.com; <br /> &copy; 2007-2011 TWiki:TWiki.TWikiContributor |
|  License: | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] |
|  Plugin Version: | 21289 (2011-05-14) |
|  Change History: | <!-- versions below in reverse order -->&nbsp; |
|  2011-05-14: | TWikibug:Item6701: Small fix in Config.spec -- TWiki:Main.PeterThoeny |
|  2010-05-04: | TWikibug:Item6433: Doc improvements; replacing TWIKIWEB with SYSTEMWEB |
|  Dec 2007: | add !AttachAsUser |
|  Nov 2007: | initial release |
|  Dependencies: | None |
|  Plugin Home: | http://twiki.org/cgi-bin/view/Plugins/UpdateAttachmentsPlugin |
|  Feedback: | http://twiki.org/cgi-bin/view/Plugins/UpdateAttachmentsPluginDev |
|  Appraisal: | http://twiki.org/cgi-bin/view/Plugins/UpdateAttachmentsPluginAppraisal |

__Related Topics:__ %SYSTEMWEB%.TWikiPlugins, %SYSTEMWEB%.DeveloperDocumentationCategory, %SYSTEMWEB%.AdminDocumentationCategory, %SYSTEMWEB%.TWikiPreferences
