Sometimes you need to execute a script to do some maintenance work and you know you will only need it once. On Elgg 1.x I did it by booting the engine with
dirname(__DIR__) . "/engine/start.php";
then added my code, placed the script in the Elgg root directory and then called it from the browser.
As the docs say the code above should no longer be used. I did it with
require_once dirname(__DIR__) . "/vendor/autoload.php";
\Elgg\Application::start();
and I'm pretty sure that worked in the past.
But now on Elgg 2.3 and also on master it no longer works (I don't know with which version of Elgg 2 it stopped working exactly). Instead of executing the script Elgg tries to serve the "scriptname" page - and doesn't find it of course.
What to do now instead? Is there any other way apart from creating a full "maintenance" plugin that allows to trigger the execution of the script?
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- ihayredinov@ihayredinov
ihayredinov - 0 likes
- iionly@iionly
iionly - 0 likes
- ihayredinov@ihayredinov
ihayredinov - 0 likes
- iionly@iionly
iionly - 0 likes
- ihayredinov@ihayredinov
ihayredinov - 0 likes
- Rohit Gupta@Rohit_1990_3676
Rohit Gupta - 0 likes
- Steve Clay@steve_clay
Steve Clay - 0 likes
- iionly@iionly
iionly - 0 likes
You must log in to post replies.Use run_function_once()
Not happy about using run_function_once(). It leaves an entry in the database and you would also not get output to be displayed directly on screen (which is useful when doing a dry run for testing a script that alters the database before you actually let the changes happen).
Is it intentional that you can't run a script anymore like this or has it only been a side-effect of another change (e.g. made for performance gain)?
It should work. I don't recall any changes to app booting.
I've tested on Elgg 2.3.0 (with 3rd party plugins installed) and additionally on a master test installation (without any 3rd party plugins). It failed to work for me in both cases.
Are you requiring the correct vendor path? What's happening when you run start()? How are you accessing your script?
@iionly
I am using elgg 2.2.2 and the "require_once dirname(__DIR__) . "/vendor/autoload.php" is still working in this version of Elgg.
Cmon, you gotta give us more info, from error_log or ini_set('display_errors', 1) before. FWIW standalone script works fine for me in 2.3.
Sorry, sorry, sorry. It does work fine indeed!
I made such a very stupid mistake. The code was perfectly alright. Just the name I saved the script as was different than the name I called the script with! Uff! Sometimes it's better to go to sleep instead of trying to finish something.