Seite 1 von 1

Create wE document folder dynamically

Verfasst: Mo 10. Okt 2016, 13:12
von ounos
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.

Re: Create wE document folder dynamically

Verfasst: Mo 10. Okt 2016, 23:39
von WBTMagnum
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

Re: Create wE document folder dynamically

Verfasst: Di 11. Okt 2016, 13:24
von mokraemer
@Sascha: I suppose your changes are correct, so please make a commit, I'll have a look on it after the commit.

Re: Create wE document folder dynamically

Verfasst: Di 11. Okt 2016, 17:10
von WBTMagnum
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?

Re: Create wE document folder dynamically

Verfasst: Di 11. Okt 2016, 18:27
von mokraemer
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.

Re: Create wE document folder dynamically

Verfasst: Di 11. Okt 2016, 20:28
von WBTMagnum
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

Re: Create wE document folder dynamically

Verfasst: Mi 12. Okt 2016, 15:06
von mokraemer
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?!

Re: Create wE document folder dynamically

Verfasst: Mi 12. Okt 2016, 21:00
von WBTMagnum
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

Re: Create wE document folder dynamically

Verfasst: Di 25. Okt 2016, 11:28
von WBTMagnum
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