Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Batch actions doesn't work on secondary languages


Reply


5 Posts   1499 Views

Avatar
heidgert

Community Member, 16 Posts

28 July 2009 at 5:08am

Edited: 28/07/2009 5:08am

I've finished translating our entire site into swedish - all in draft mode. (saving lots of time with the excellent CMS Batch Action module found here http://www.silverstripe.org/customising-the-cms/show/262215)

I'm now ready to go live and wanted to perform a batch action to publish all pages. This gives a 'Javascript Parse Error' on my live site (haven't yet been able to log the full error).

On my dev site it gives a 'Undefined error', looking like this in my log:
[27-Jul-2009 06:52:18] Warning at D:\Wamp Websites\cms\code\CMSBatchAction.php line 42: Invalid argument supplied for foreach() (http://localhost/admin/batchactions/publish)

If I use the batch action on the default language (en_US) it works fine.

Have someone else experienced this? What can I do? I'd rather not publish ~200 pages manually...

Avatar
Mario...

Community Member, 14 Posts

16 June 2011 at 8:22pm

The problem is that the default language is being selected /not the current language and filtering out all the pages you want to update...

Change:
silverstripe-cms/code/CMSMain.php Line 91

$this->Locale = Translatable::default_locale();

to

$this->Locale = Translatable::choose_site_locale();

Worked for me here:
https://github.com/mmichelli/silverstripe-cms
and
https://github.com/mmichelli/sapphire

Avatar
madhamster

Community Member, 2 Posts

16 October 2011 at 12:21pm

That doesn't solve the problem :(

The problem is that regular admin page, uses "locale" $_GET param to determine what locale we are currently in, but ajax requests for batch actions don't have that parameter set!

So when we are not working in primary locale, ajax url for batch action looks something like:

"/admin/batchactions/deletefromlive/applicablepages?csvIDs=184"

This one for example looks if we can delete pages from "Live", BUT there is no GET locale param set!!
It should look like:

"/admin/batchactions/deletefromlive/applicablepages?locale=ru_RU&csvIDs=184"

Because of that for DataObject::get() methods in BatchAction handler we get queries like:

SELECT ... WHERE ... SiteTree.ID IN (184) AND Locale = 'en_US' <-- DEFAULT LOCALE!!!

Page with id 184 exists, BUT ONLY IN ru_RU locale. So we get grayed out checkboxes, "undefined" and "javascript parse error" messages, cause DataObject::get() returns NULL, and foreach loop that works after it throws up an error and so on...

choose_site_locale() method uses $_GET param to determine the locale, BUT as i said before its no set un current ajax url request.

So now, we have to somehow pass locale parameter into ajax requests...

Avatar
martimiz

Forum Moderator, 1107 Posts

18 October 2011 at 3:51am

This was bugging me as well, so I went adding locales almost everywhere, finally narrowing it down to two files, two lines of code, and now it seems to work for me.

1.
/cms/templates/Includes/CMSMain_left.ss:

find the following form: <form class="actionparams" style="border:0" id="batchactions_options" action=""> and add a new hidden field like so:

<input type="hidden" name="locale" id='batchactions_options_locale' value="$Locale" />

Then do a ?flush=1

2.
/cms/javascript/CMSMain_left.js:

find the folowing code (line 461 or thereabouts)

var applicablePagesURL = $('choose_batch_action').value + '/applicablepages?csvIDs=' + ids.join(',');

and add the locale like this:

var applicablePagesURL = $('choose_batch_action').value + '/applicablepages?csvIDs=' + ids.join(',') + "&locale=" + $('batchactions_options_locale').value;

Please let me know if you find any errors in this...

Avatar
Ruud

Community Member, 3 Posts

20 April 2012 at 3:04am

The latest comment from martimiz did work for me! It should be added to the silverstripe source!