Create wE document folder dynamically

Benutzeravatar
ounos
Member
Beiträge: 44
Registriert: Mi 6. Aug 2014, 11:09

Create wE document folder dynamically

Beitragvon ounos » Mo 10. Okt 2016, 13:12

Hello,

is there any proper way to create a wE document folder dynamically using php ?

I already use the following code:

Code: Alles auswählen

$folder = new we_folder();
$folder->initByPath($a_path_var);

which will create successfully the desired folder BUT if I delete the folder once, it cannot be recreated and I get the following error:

Code: Alles auswählen

File: DOCUMENT_ROOT/webEdition/we/include/we_classes/base/we_base_file.class.php
--------------------------------------------------------------------------------
Line: 361
--------------------------------------------------------------------------------
Text: Could not create local Folder at File.php/createLocalFolderByPath(): 'SECURITY_REPL_DOC_ROOT/webEdition/../path/to/be/created/'

I checked a bit the class mentioned in the log, but I can't figure out the reason it fails.
Any ideas ? Thank you in advance.

Online
WBTMagnum
webEdition Partner
webEdition Partner
Beiträge: 1319
Registriert: Di 7. Mär 2006, 16:50
Kontaktdaten:

Re: Create wE document folder dynamically

Beitragvon WBTMagnum » Mo 10. Okt 2016, 23:39

Here is some additional information:
  • webEdition 7.0.0.0
  • multi-site setup enabled

My tests show that the initial folder creation via PHP is not working correctly. The folder is only created in webedition's internal site folder, but not in the public folder (it's a multi-site folder). Also at this point an error message, similar to the one ounos already posted, is created.

If I call the folder creation part manually, the folder is created successfully:

Code: Alles auswählen

mkdir('SECURITY_REPL_DOC_ROOT/webEdition/../path/to/be/created/', 0755, true);


I'm currently at a loss, why this is failing.


@marc:
While examining the code I added some inline documentation to "we_base_file.class.php" and "we_folder.class.php". Additionally I fixed a minor bug in "we_folder.inc.php@experimentalMS". Shall I simply push these changes via SVN or do you prefer a patch?


Cheers,
Sascha

mokraemer
Senior Member
Beiträge: 2366
Registriert: So 8. Aug 2010, 01:23
Wohnort: Mainz

Re: Create wE document folder dynamically

Beitragvon mokraemer » Di 11. Okt 2016, 13:24

@Sascha: I suppose your changes are correct, so please make a commit, I'll have a look on it after the commit.
webEdition-Kern-Entwickler

Online
WBTMagnum
webEdition Partner
webEdition Partner
Beiträge: 1319
Registriert: Di 7. Mär 2006, 16:50
Kontaktdaten:

Re: Create wE document folder dynamically

Beitragvon WBTMagnum » Di 11. Okt 2016, 17:10

Core code changes:
Committed revision 12988.

Regarding the folder problem:
Any idea what might cause this behaviour? Do we miss something in the path creation? Might this be related to the multi-site setup?

mokraemer
Senior Member
Beiträge: 2366
Registriert: So 8. Aug 2010, 01:23
Wohnort: Mainz

Re: Create wE document folder dynamically

Beitragvon mokraemer » Di 11. Okt 2016, 18:27

regarding the "fix" it was only on the error-message, really nothing that matters.
Regarding folder creation, the proper way should be:

Code: Alles auswählen

$folder=new we_folder();
$folder->we_new(FILE_TABLE,$parentID,$name);
$folder->we_save();


At least that is the way it is created by the gui.
webEdition-Kern-Entwickler

Online
WBTMagnum
webEdition Partner
webEdition Partner
Beiträge: 1319
Registriert: Di 7. Mär 2006, 16:50
Kontaktdaten:

Re: Create wE document folder dynamically

Beitragvon WBTMagnum » Di 11. Okt 2016, 20:28

mokraemer hat geschrieben:regarding the "fix" it was only on the error-message, really nothing that matters.


No, that's not the fix I meant. I was talking about:

Code: Alles auswählen

- $folder->IsNotEditable = $IsClassFolder;
+ $folder->IsNotEditable = $IsNotEditable;


mokraemer hat geschrieben:Regarding folder creation, the proper way should be:

Code: Alles auswählen

$folder=new we_folder();
$folder->we_new(FILE_TABLE,$parentID,$name);
$folder->we_save();


At least that is the way it is created by the gui.


Thanks for the intel! This is exactly what happens in initByPath(). So the prince... problem must be hidden in another castle. We'll continue our search.

Cheers,
Sascha

mokraemer
Senior Member
Beiträge: 2366
Registriert: So 8. Aug 2010, 01:23
Wohnort: Mainz

Re: Create wE document folder dynamically

Beitragvon mokraemer » Mi 12. Okt 2016, 15:06

WBTMagnum hat geschrieben:No, that's not the fix I meant. I was talking about:

Code: Alles auswählen

- $folder->IsNotEditable = $IsClassFolder;
+ $folder->IsNotEditable = $IsNotEditable;


Sorry there is no such commit in the svn repo.
Even in 7.1 this property doesn't exist anymore.

WBTMagnum hat geschrieben:Thanks for the intel! This is exactly what happens in initByPath(). So the prince... problem must be hidden in another castle. We'll continue our search.

This is not guarantied in my version. The proper way is the way I described it. And as a matter of fact it works in the GUI. Do you use Multidomain? Are you sure all symlinks point right, and your test of mkdir took place with the right (web)user in the right directory?!
webEdition-Kern-Entwickler

Online
WBTMagnum
webEdition Partner
webEdition Partner
Beiträge: 1319
Registriert: Di 7. Mär 2006, 16:50
Kontaktdaten:

Re: Create wE document folder dynamically

Beitragvon WBTMagnum » Mi 12. Okt 2016, 21:00

mokraemer hat geschrieben:
WBTMagnum hat geschrieben:Thanks for the intel! This is exactly what happens in initByPath(). ...

This is not guaranteed in my version. The proper way is the way I described it. And as a matter of fact it works in the GUI.


I just had a look at the initByPath() function in trunk. It performs pretty much that same steps you described. But anyhow, we will try the approach you suggested.

mokraemer hat geschrieben:Do you use Multidomain?

Yes, it's a multi-domain setup.


mokraemer hat geschrieben:Are you sure all symlinks point right

Quite sure, since everything else works pretty well.


mokraemer hat geschrieben:and your test of mkdir took place with the right (web)user in the right directory?!

Yes, I used the webuser and invoked mkdir() on the right location. As I mentioned above, this did succeed. But the supposedly same mkdir() called via initByPath() failed.


Thanks for your inputs / suggestions,
Sascha

Online
WBTMagnum
webEdition Partner
webEdition Partner
Beiträge: 1319
Registriert: Di 7. Mär 2006, 16:50
Kontaktdaten:

Re: Create wE document folder dynamically

Beitragvon WBTMagnum » Di 25. Okt 2016, 11:28

After some investigation we found the source of the problem. It is in fact multi-domain related. See bugbase ticket #11110 for further details and the patch we came up with.

Discussions regarding this issue can continue in the ticket.

Cheers,
Sascha


Zurück zu „webEdition Basic Version“

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast