Using the [inline:#] method for attaching images is very fragile. All it takes is for a replacement image to be uploaded and inline loses its link to the image.

Instead, I propose retaining the # notation simply as a shortcut while authoring a page but always storing tags in nodes with filenames.

Inline would need to intercept the form submission, work out what the filename is for each # and convert the tag to the filename notation.

Comments

sun’s picture

+1 sounds well.
With the 4.7 forms api this shouldn't be too hard to implement.

sun’s picture

Component: User interface » Code
Status: Active » Needs review
StatusFileSize
new3.53 KB

Here we go. Attached patch slightly replaces every occurence of # in [inline:#] or [inline:#=title] with the corresponding file name of actual node attachments. This happens everytime a node is being updated oder saved.

Since I'm currently launching a new site I thought it would be much more safe if inline attachments would be stored safe. So I have realized your idea.

Bèr Kessels’s picture

Did not test the code, but the patch looks solid and clean to me.

sun’s picture

Is there a demand for a migration script? I'm considering that this patch only works with 4.7 forms API and people would have to migrate their Drupal installation to 4.7, so I would say, new installations of Drupal 4.7 incl. inline module will be safe in the future. However, there are a lot of people who used inline module in previous versions.

With the requirement of Drupal 4.7 in mind I could imagine an additive invocation of the new function to convert any numeric inline tags to named ones while contents are only viewed, not edited.
For already broken attachments there would be no difference. But those working tags would be converted to a safer syntax.

Additionally I want to point out that this patch does not alter inline tags in preview mode - deliberately. While still authoring a node, numeric inline tags are much more usable.

Richard Archer’s picture

The upgrade path is actually where I got stuck on this patch.

I think it would be very nice to convert all old-style inline:# tags. But there doesn't seem to be a way for a module to interface with the upgrade system. And there's no easy way for inline to retrieve a list of all inline tags that are being used in a site.

I guess you'd just need to add some code to inline that looked for these old tags and converted them on-the-fly. And if the node is saved, then write out the new format. Which seems to be a fair bit of baggage to be carrying around.

Bèr Kessels’s picture

Any module can interface with the upgrade system. There is a handbook page about this, one that I cannot find right now :(.

I have used it to change a filter in the past. just do a LOT of node-loads, parse the data and do a node-save. It might timeout, but even that can be acted upon, look at how the revisions upgrade handled that.

Bèr.

sun’s picture

Status: Needs review » Reviewed & tested by the community

just for the record: isn't the upgrade possibitility another issue?

In between I can confirm that the patch works well for creating and updating contents. This fixes at least any content which is edited *now*. Upgrading and migration should be an offshoot of this issue.

sun’s picture

If still complaining about the migration issue: Using the upgrade functions for modules I would suggest to rewrite all numeric inline tags by searching and replacing with a regex through the database. So conversion would be done at one time. Any concerns or better suggestions?

sun’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.83 KB

Updated patch

  • does not replace numeric tags for attachment.module, since attachments are allowed to have identical file names. In general, I consider attachment.module buggy allowing more than one file with the same file name as attachment for one node. But as long as this is possible with attachment.module we can't replace those numeric tags with the corresponding file names.
  • now properly replaces files attached by upload.module, since those are stored with their database file ID (fid) instead of just counted.
sun’s picture

Version: 6.x-2.x-dev » 5.x-1.x-dev
Assigned: Richard Archer » sun
Category: feature » bug

This is a bug, not a feature. And this should get into the new DRUPAL-5 branch immediately to kinda 'protect' any new users of inline.

Some thoughts on the need for migration: IIRC, numeric assignments get only broken if a new (upload) attachment is added or an existing (upload) attachment is removed. So regarding migration, the additional solution for this problem should be to transform existing inline tags in front of displaying a node edit form, right?

sun’s picture

StatusFileSize
new3.15 KB

And here follows the magic patch! Replaces numeric inline tags with named ones

  • in front of displaying the node edit form (converting old tags) and
  • after submitting the node edit form (converting new tags).
sun’s picture

Title: Re-think the inline:# use case » Numeric tag assignments get lost after file attachment updates
Status: Needs review » Patch (to be ported)

As mentioned before, this is a serious issue on certain sites.
Committed to HEAD and DRUPAL-5.
Changed title to better suit this issue.

Backport for DRUPAL-4-7 needed.

sun’s picture

Status: Patch (to be ported) » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)