Author Topic: OneForAll deletes its own page  (Read 501 times)

Offline CodeALot

  • Posts: 407
  • Gender: Male
OneForAll deletes its own page
« on: February 12, 2019, 03:51:55 PM »
On several sites using OneForAll I noticed that, for reasons unknown to me, the 'source'page where the OFA-module resides, can disappear if the user (admin/editor) does "something" wrong. What they do, I don't know. All I know is that the pagefile disappears and that is annoying.

So what do I mean?
  • OFA is the only section on page "Example"
  • On the webserver, there is a file called /pages/example.php
  • If the admin or any other editor adds a record/item to the OFA module and does "something" wrong (NO idea what, I can't reproduce the error) the file /pages/example.php is deleted.
  • To solve this, I have to go into SFTP and copy the file again from my local backup.

What can I do to prevent this from happening? Can I 'lock' the file using read/write rights? This file never needs to be edited anyway, so why not "glue" it into place?

Offline dbs

  • Betatester
  • **
  • Posts: 7788
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: OneForAll deletes its own page
« Reply #1 on: February 12, 2019, 04:02:56 PM »
Which old version of OFA you use?
The latest version from Add-ons Repo don't do this.

Offline Ruud

  • Posts: 3647
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: OneForAll deletes its own page
« Reply #2 on: February 12, 2019, 04:20:58 PM »
I used v 1.0.9 a lot and have seen the same problem. It sometimes happens whenever a new item is created.
I also could not reproduce the problem, but the simpel fix to restore the overviewpage is to go into the settings of that page and click the "save" button.



Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #3 on: February 12, 2019, 04:33:01 PM »
but the simpel fix to restore the overviewpage is to go into the settings of that page and click the "save" button.
Ah that's a good one :)

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #4 on: February 12, 2019, 04:35:11 PM »
Which old version of OFA you use?
The latest version from Add-ons Repo don't do this.
It's not the latest version, but because many modifications were made (not in the modify-scripts but in the viewing scripts) upgrading is not an option. I was mostly wondering how this could be happening and what could be done to prevent it.

info.php claims it's 1.0.9

Offline dbs

  • Betatester
  • **
  • Posts: 7788
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: OneForAll deletes its own page
« Reply #5 on: February 12, 2019, 04:45:12 PM »
I also know the bug and was pleased that Dietmar could fix it in the following versions. But I also know that upgrades are difficult when you have made your own adjustments.
My solution was like yours, copy a backup of the accessfile to /pages.

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #6 on: February 12, 2019, 08:19:49 PM »
Thanks dbs for your replies. Maybe if Dietmar could reveal what caused the bug, I may be able to fix my version?

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #7 on: February 12, 2019, 08:22:26 PM »
v 1.0.7 already mentions:
Bugfix: For items without access file the field link is empty and hence the page access file will be deleted instead of the item access file (reported by dbs, thanks to Ruud)


Sounds like my problem, although I am using 1.0.9... (confused now :-)

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #8 on: February 26, 2019, 10:00:27 AM »
Thanks dbs for your replies. Maybe if Dietmar could reveal what caused the bug, I may be able to fix my version?

Anyone? Pretty please? :)

Offline dbs

  • Betatester
  • **
  • Posts: 7788
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: OneForAll deletes its own page
« Reply #9 on: February 26, 2019, 11:24:29 AM »
You can't upgrade to latest version?
For security and the future.

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #10 on: February 26, 2019, 11:26:48 AM »
It's a very heavily modified version so that would mean a lot of work...

Does the new version allow more than one person to add records at the same time? (This also is a problem in the version we're using now)

Offline dbs

  • Betatester
  • **
  • Posts: 7788
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: OneForAll deletes its own page
« Reply #11 on: February 26, 2019, 11:32:22 AM »
Good question.
Experience says two are one too many at the same time.

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #12 on: February 26, 2019, 11:44:38 AM »
Good question.
Experience says two are one too many at the same time.
:-)

I think the problem starts when two people start adding an item, where the script will simply look into the database for the next available item_id - and while those new items aren't saved, they will try to use the same item_id upon saving.
So when editor 1 saves his item, it is overwritten once editor 2 saves it after editor 1.
The solution would be to create a database record as soon as you start adding an item, which would "claim" the new item_id already.

...but I have no idea how to make it do that :-]

Offline jacobi22

  • Posts: 5683
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: OneForAll deletes its own page
« Reply #13 on: February 26, 2019, 12:28:48 PM »
OFA works with this scheme
step#1 - add a empty item into the database, only item_id, section_id, page_id, the redirect to the modify_item to edit exact this ID
step#2 - modify this added item

so, its not possible for the add-process, that two users add the same item_id

but... it's possible, that two people edit a existed item at the same time and one overwrite the content from the other. the latest save win's   - and: a problem like this (two people works on the same article) is possible in nearly every system


P.S.: its not possible, that two users use the exact same millisecond in the add-process, one of them is faster and get the first ID
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #14 on: February 26, 2019, 01:07:42 PM »
OFA works with this scheme
step#1 - add a empty item into the database, only item_id, section_id, page_id, the redirect to the modify_item to edit exact this ID
step#2 - modify this added item

so, its not possible for the add-process, that two users add the same item_id

I am sure that's how it should work. But it doesn't.

To test this, I made a 100% clean install:

WB 2.12.1
OneForAll 2.0.2.23
PHP 7.3


Opened two different browsers (Chrome and Firefox)

Clicked "Add item" on Chrome.  Address bar shows:
Code: [Select]
modify_item.php?page_id=1&section_id=1&item_id=1&from=add_itemClicked "Add item" on Firefox. Address bar shows:   
Code: [Select]
modify_item.php?page_id=1&section_id=1&item_id=1&from=add_item
So there's some sort of bug there. It shows that it IS possible to add a new item and still have the same item_id as someone else adding an item at that same moment.

Offline jacobi22

  • Posts: 5683
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: OneForAll deletes its own page
« Reply #15 on: February 26, 2019, 01:32:25 PM »
i dont have the time at time moment, because, the doc is waiting for me, but if you want,

1. go to WB_Settings -> Advanced Settings and set Redirect after.... to -1 (that means, no automatically redirect, you have to push the OK-button)
2. now add a new item in browser one, click only one time on the OK- or Success-Button, the page reloads and show the same again, but dont click here on the buttons
3. take a look into the database - do you have there a new entry in your module table with only section & page-id? remember the item-id from this entry
4. now go to the next browser and do the same, add new item, look into the database
5. now you can click in both browsers on the (second) success-button
5. compare the item_id's from the database with the item_id's from the link in browser adressline

i'll do that, if i'm coming back at home later
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #16 on: February 26, 2019, 01:43:54 PM »
Tested as described. If Redirect after.... to -1 it works OK, it seems. Two seperate item_id's are created in the database
With Redirect after 1 it fails. Only one item_id is created in the database and both browsers try to edit that item.


It's even worse.

Here's what I found.
Enter ADMIN. Select the OFA page. Click "Add new item". --> new item_id is made in the database

New browser: Enter Admin. Select OFA page (  admin/pages/modify.php?page_id=1   ) DO NOTHING.
The OFA-module then deletes the empty item_id that was created in the other browser

Redirect-settings are not an issue in this case.
« Last Edit: February 26, 2019, 02:01:07 PM by CodeALot »

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #17 on: February 26, 2019, 02:04:11 PM »
In other words:
If someone is working on a new item in OFA, and someone else opens admin/pages/modify.php?page_id=1, the item of the first person is removed from the database (if it has not been saved before yet)
( table: wb_mod_oneforall_it ems )

Offline dbs

  • Betatester
  • **
  • Posts: 7788
  • Gender: Male
  • tioz4ever
    • WebsiteBaker - jQuery-Plugins - Module - Droplets - Tests
Re: OneForAll deletes its own page
« Reply #18 on: February 26, 2019, 02:07:18 PM »
Can confirm this.
If two people add a item (only add, no save), two new item id's will created in the db.
If now one of them breaks off, both id's will deleted from the db.

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #19 on: February 26, 2019, 02:07:46 PM »
And I think it's all caused by these lines (50 - 52) in /modules/oneforall/modify.php

Code: [Select]
// Delete empty Database records
$database->query('DELETE FROM `'.TABLE_PREFIX.'mod_'.$mod_name.'_items` WHERE `page_id` = '.(int)$page_id.' and `section_id` = '.(int)$section_id.' and `title` = \'\' ');
$database->query('ALTER TABLE `'.TABLE_PREFIX.'mod_'.$mod_name.'_items` AUTO_INCREMENT = 1');

Because: as long as the item does not have a title yet, it should be deleted.

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 2993
  • Gender: Female
Re: OneForAll deletes its own page
« Reply #20 on: February 26, 2019, 03:05:01 PM »
Unnamed (uncompleted) records must be deleted on cancel, otherwise the strange, old and ever-continued, creation of new records in WB modules would result in countless empty, invalid records.
It is well known that WB is very often not multi-user capable when creating new records.
But do not worry, it is already working on a new, secure and stable algorithm.

Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"You have to take the men as they are… but you can not leave them like that !" :-P
Das tägliche Stoßgebet: Oh Herr, wirf ihnen Hirn vom Himmel !

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #21 on: February 26, 2019, 03:46:21 PM »
Unnamed (uncompleted) records must be deleted on cancel, otherwise the strange, old and ever-continued, creation of new records in WB modules would result in countless empty, invalid records.
I agree. On cancel. But not on entering the module :)

Keep up the good work on multi-user capabilities. Can't wait :)

Offline jacobi22

  • Posts: 5683
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: OneForAll deletes its own page
« Reply #22 on: February 26, 2019, 04:08:16 PM »
simple solution for this case - but not 100% save in every case

if you set in add_items.php also the "modified_when" - Timestamp, you can use a timer in the delete-sql in modify.item Ln 51, maybe 24 hours. result: item without title will not be deleted in the next 24 hours after adding this item

other solution, you set a title + modified_when-timestamp in add_item.php,  maybe the word "Title + Timestamp" and you compare this word-combination with the modified_when-Timestamp and remove it from the input-field, if you have a exact match. then you have a empty title-field in the modify_item.php, but a filled field in database and nothing will be deleted

multi-user capabilities sound's good, but it needs changes on all modules too
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #23 on: February 26, 2019, 04:10:50 PM »
Made a fix myself.


In oneforall/add_item.php I added a user identifier ( $editor ) and I added the modified_by to be set to the user_id ( $editor ) upon creation of a new record:
Code: [Select]
// Insert new row into database
$editor= $_SESSION['USER_ID'];
$Sql =  'INSERT INTO `'.TABLE_PREFIX.'mod_'.$mod_name.'_items` SET '
                   .  '`section_id`= '.$section_id.' , '
                   .  '`page_id`= '.$page_id.', '
                   .  '`position`= '.$position.', '
                   .  '`modified_by`= '.$editor.', '
                   .  '`active`= 0, '
                   .  '`link` = \'\', '
                   .  '`description` = \'\' ';
$database->query($Sql);

So every new (empty) record has the user_id of the person who made the record.

In oneforall/modify.php I changed the segment that deletes empty records. It now checks if it has an empty title and if it is made by you. ( $editor )
Code: [Select]
// Delete empty Database records
$editor = $_SESSION['USER_ID'];
$database->query("DELETE FROM `".TABLE_PREFIX."mod_".$mod_name."_items` WHERE page_id = '$page_id' and section_id = '$section_id' and title = '' and modified_by =". $editor);

This causes the modify.php to delete only empty records made by yourself, not by someone else who may still be working on a new record.

So far, while testing this, it seems to work. No empty records, and no deleted records made by someone else...
« Last Edit: February 26, 2019, 04:16:18 PM by CodeALot »

Offline CodeALot

  • Posts: 407
  • Gender: Male
Re: OneForAll deletes its own page
« Reply #24 on: February 27, 2019, 11:17:35 AM »
(Well I thought it was pretty clever ;)

 

postern-length