-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved auto activation of language to an own task
- Loading branch information
1 parent
fcc52b1
commit 4d0bb97
Showing
5 changed files
with
68 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
class ActivateLanguageTask extends BuildTask { | ||
|
||
protected $title = 'Activate a language for all pages'; | ||
protected $description = 'Select one language to activate for all pages and dataobjects. /dev/tasks/ActivateLanguageTask.php?en=1'; | ||
protected $enabled = true; | ||
|
||
function run($request) { | ||
$this->ActivatLang(); | ||
|
||
DataObject::flush_and_destroy_cache(); | ||
} | ||
function ActivateLang(){ | ||
$idArray = explode('&', $_SERVER["QUERY_STRING"]); | ||
|
||
if (sizeof($idArray) > 1) { | ||
foreach ($idArray as $ignore => $avPair) { | ||
list($index, $value) = explode("=", $avPair); | ||
$allowed_langs = array_keys(self::map_locale()); | ||
print_r($allowed_langs); | ||
if ($value && in_array($index, $allowed_langs)) { | ||
if ($index == Multilingual::default_lang()) { | ||
$fieldname = "LangActive"; | ||
} else { | ||
$fieldname = "LangActive_" . $index; | ||
} | ||
|
||
//fix dataobjects | ||
$sqlquery = new SQLQuery("*", "MultilingualDataObject"); | ||
$results = $sqlquery->execute(); | ||
|
||
foreach ($results as $obj) { | ||
if (!empty($obj["ClassName"])) { | ||
$object = DataObject::get_by_id($obj["ClassName"], $obj["ID"]); | ||
$object->$fieldname = true; | ||
$object->write(); | ||
} | ||
} | ||
|
||
|
||
//fix pages | ||
$sqlquery = new SQLQuery("*", "MultilingualPage"); | ||
$results = $sqlquery->execute(); | ||
|
||
foreach ($results as $obj) { | ||
$object = DataObject::get_by_id("MultilingualPage", $obj["ID"]); | ||
$object->$fieldname = true; | ||
if ($object->isPublished()) { | ||
$object->doPublish(); | ||
} else { | ||
$object->write(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters