Page 1 of 1

serendipity_event_entrylastmodified upgrade & comments

Posted: Fri Dec 02, 2005 12:38 pm
by JWalker
I made an improvement of serendipity_entry_lastmodified: and now it emits Last modified on ... when the entry really was modified. If there was no modification, it emits something like Not modified. Here is the code:

[was]

Code: Select all

$eventData[$i]['add_footer'] .= sprintf(PLUGIN_EVENT_ENTRYLASTMODIFIED_HTML, serendipity_formatTime(DATE_FORMAT_SHORT, $eventData[$i]['last_modified']));
[changed to]

Code: Select all

$tm_timestamp = sprintf(PLUGIN_EVENT_ENTRYLASTMODIFIED_HTML, serendipity_formatTime(DATE_FORMAT_SHORT, $eventData[$i]['timestamp']));
$tm_last_modified = sprintf(PLUGIN_EVENT_ENTRYLASTMODIFIED_HTML, serendipity_formatTime(DATE_FORMAT_SHORT, $eventData[$i]['last_modified']));
    if (strcmp($tm_timestamp,$tm_last_modified) != 0) {
        $eventData[$i]['add_footer'] .= $tm_last_modified;
    } else {
        $eventData[$i]['add_footer'] .= sprintf('<br /><div style="text-align: right">PLUGIN_EVENT_NOTMODIFIED</div>');
    }
If this 'upgrade' is welcome, may it happens official in CVS ? Or may there be a config option to use the new behaviour or not ? Or for not modified entries config option to show 'Not modified' or nothing ? I can do it, but I'd like to hear some opinions here before that.

And now comments. First I tried to compare $eventData[$i]['timestamp'] and $eventData[$i]['last_modified'] and wondered why these always were different nevertheless that I did not made any changes to the test entry. At last I made a database select and here is the result:

Code: Select all

mysql> select timestamp,last_modified from s9y_entries;
+------------+---------------+
| timestamp  | last_modified |
+------------+---------------+
| 1132666902 |    1132691164 |
| 1132668434 |    1133517322 |
| 1133508101 |    1133508172 |
| 1133518270 |    1133518282 | <==============
+------------+---------------+
4 rows in set (0.00 sec)
Last entry is that I did not modified but there is different values for timestamp and last_modified fields. May be these receive their initial values independently ? I think that when the entry is saved for the first time in the database last_modified must get its value from timestamp.

Re: serendipity_event_entrylastmodified upgrade & commen

Posted: Fri Dec 02, 2005 1:16 pm
by garvinhicking
Such a patch would be welcome, yes. But the detection logic of it, as you are asking for, will make this problematic.

The reason is this:

The 'last_modified' is set according to the current timestamp of the server when the entry is stored.

The 'timestamp' option can be set by the user, in the date box of the entry form. Thus it always holds the timestamp when the user STARTED creating his entry.

So, if you start creating your entry at 12:00pm, and finish it by 12:05pm, the 'last_modified' stamp witll be 12:05pm, and 'timestamp' will be 12:00pm.

The reason for this is to let the user be able to define the time when his entry shall be posted, but still store the actual date when it was written to detect when updates are made to the entry and when it was actually stored.

You could include a timespan like "only display last_modified if it is within 10 minutes of the timestamp range", but then you would show entries as modified which take 20 minutes to write.

Regards,
Garvin

Posted: Fri Dec 02, 2005 4:30 pm
by JWalker
functions_entries.inc.php, function serendipity_updertEntry($entry).
This code:

Code: Select all

    if (!is_numeric($entry['timestamp'])) {
        $entry['timestamp'] = time();
    }

    if (!isset($entry['last_modified']) || !is_numeric($entry['last_modified'])) {
        $entry['last_modified'] = time();
    }
Is it possible to modify second if that $entry['last_modified'] to get value of $entry['timestamp'] or time() using some logic ?

Posted: Sat Dec 03, 2005 12:57 am
by garvinhicking
Hm, I don't know. You might want to try it out -- but this logic should only apply for entries not written with the HTTP admin suite, only for XMLRPC posting or so. When posting an entry via the admin suite, the timestamp and last_modified values should always be set...

Regards,
Garvin

new revision

Posted: Sat Dec 03, 2005 9:03 pm
by JWalker
Hi, Garvin,

I tried and was successful:
functions_entries.inc.php, function serendipity_updertEntry($entry):
1) commented

Code: Select all

//if (!isset($entry['last_modified']) || !is_numeric($entry['last_modified'])) {
//        $entry['last_modified'] = time();
//}
2) added $entry['last_modified'] = ... downwards in the true and false parts of

Code: Select all

if (!is_numeric($entry['id'])) {
just before serendipity_db_insert/update calls:

Code: Select all

$entry['last_modified'] = $entry['timestamp'];
$res = serendipity_db_insert('entries',$entry);

Code: Select all

$entry['last_modified'] = time();
$res = serendipity_db_update('entries', array('id' => $entry['id']), $entry);
This works almost fine with the new version of the plugin with one drawback. When one changes the date of an entry, but not the entry itself, the $entry['last_modified'] is changed and thus the entry is reported as changed. That is because the date can be changed in edit entry page.

I've just committed the serendipity_event_entrylastmodified plugin in CVS. Changes are in serendipity_event_lastmodified.php and in language files ('bg', 'en') - added new strings. Also, I removed HTML tags in these strings and put them into the code and as a result old lang files will not work with new plugin file (by now ('de', 'ja')). You may want to commit functions_entries.inc.php in SVN too.

Regards,

Re: new revision

Posted: Sun Dec 04, 2005 12:47 pm
by garvinhicking
Hm, this change might easily break some very important things, so I cannot commit it right away but need to investigate it very thorougly.

Could you send me a complete DIFF to see what you changed? That makes it easier for me to have an exact look.

Regards,
Garvin