ezpublish-legacy icon indicating copy to clipboard operation
ezpublish-legacy copied to clipboard

Fix EZP-21913: ezpublish:legacy:script break with usage of globals in scripts

Open lolautruche opened this issue 11 years ago • 8 comments

https://jira.ez.no/browse/EZP-21913 https://jira.ez.no/browse/EZP-21941

Replaces #826 . Complementary PR: #831

This PR replaces usage of flawed global keyword by closures. This allows to import context from inside the script. Reason: These variables are not global anymore when scripts are executed via ezpublish:legacy:script.

Scripts to fix up

  • [x] changelog2xmltext.php
  • [x] clusterize.php
  • [x] convertprice2multiprice.php
  • [x] ezconvertdbcharset.php
  • [x] ezflowupgrade.php
  • [x] ezwebincommon.php
  • [x] ezwebininstall.php
  • [x] ezwebinupgrade.php

lolautruche avatar Nov 07 '13 15:11 lolautruche

One note... I've thought about it, and I don't really see the point of using a closure to pass objects we have singletons for... we don't love singletons anymore, but they're here, and we might as well use them, right ?

In many cases, I also find that adding an argument is easier than changing the code (and the ordering, not cool for diffs).

I might of course be missing a point here.

bdunogier avatar Nov 07 '13 21:11 bdunogier

@bdunogier Your right, it was mostly because it makes it easier to read the code later. But if you use closure you have to make sure variable is already declared, and use statement needs to be by reference in cases variable is not object..

andrerom avatar Nov 08 '13 13:11 andrerom

All scripts have been fixed, ready for review !

lolautruche avatar Nov 08 '13 13:11 lolautruche

IMHO there should be no need for an eZDir global... there are two chdirs() in the script, a good solution is to use

$eZDir = getcwd();
// ... chdir and do stuff
chdir($eZDir);

Then just remove it completely from the showError() the other places...

joaoinacio avatar Nov 08 '13 14:11 joaoinacio

There is a mode change (10755 -> 10644) in some files scripts, is this intended?

  • bin/php/ezconvertdbcharset.php
  • bin/php/ezflowupgrade.php

joaoinacio avatar Nov 08 '13 14:11 joaoinacio

@joaoinacio: Good catch, it is not.

andrerom avatar Nov 11 '13 22:11 andrerom

@andrerom @bdunogier Should this be merged or closed ?

lolautruche avatar Jul 07 '16 07:07 lolautruche

I assume this is still an issue, so with mode change and eZDir fix we should merge this.

andrerom avatar Jul 11 '16 08:07 andrerom