2012-10-22 05:57:53 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Content.php
|
|
|
|
|
*
|
|
|
|
|
* @package workflow.engine.classes.model
|
|
|
|
|
*
|
|
|
|
|
* ProcessMaker Open Source Edition
|
|
|
|
|
* Copyright (C) 2004 - 2011 Colosa Inc.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
|
|
|
|
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2012-11-16 17:13:48 -04:00
|
|
|
//require_once 'classes/model/om/BaseContent.php';
|
2012-10-22 05:57:53 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Skeleton subclass for representing a row from the 'CONTENT' table.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* You should add additional methods to this class to meet the
|
|
|
|
|
* application requirements. This class will only be generated as
|
|
|
|
|
* long as it does not already exist in the output directory.
|
|
|
|
|
*
|
|
|
|
|
* @package workflow.engine.classes.model
|
|
|
|
|
*/
|
|
|
|
|
class Content extends BaseContent
|
|
|
|
|
{
|
|
|
|
|
public $langs;
|
|
|
|
|
public $rowsProcessed;
|
|
|
|
|
public $rowsInserted;
|
|
|
|
|
public $rowsUnchanged;
|
|
|
|
|
public $rowsClustered;
|
|
|
|
|
public $langsAsoc;
|
2012-10-19 18:07:17 +00:00
|
|
|
/*
|
2012-10-22 05:57:53 -04:00
|
|
|
* Load the content row specified by the parameters:
|
|
|
|
|
* @param string $sUID
|
|
|
|
|
* @return variant
|
|
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public static function load($ConCategory, $ConParent, $ConId, $ConLang)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
2017-12-04 13:25:35 +00:00
|
|
|
$content = ContentPeer::retrieveByPK($ConCategory, $ConParent, $ConId, $ConLang);
|
|
|
|
|
if (is_null($content)) {
|
2012-10-22 05:57:53 -04:00
|
|
|
//we dont find any value for this field and language in CONTENT table;
|
2017-12-04 13:25:35 +00:00
|
|
|
$ConValue = Content::autoLoadSave($ConCategory, $ConParent, $ConId, $ConLang);
|
2012-10-22 05:57:53 -04:00
|
|
|
} else {
|
|
|
|
|
//krumo($content);
|
|
|
|
|
$ConValue = $content->getConValue();
|
|
|
|
|
if ($ConValue == "") {
|
|
|
|
|
//try to find a valid translation
|
2017-12-04 13:25:35 +00:00
|
|
|
$ConValue = Content::autoLoadSave($ConCategory, $ConParent, $ConId, $ConLang);
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $ConValue;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 18:07:17 +00:00
|
|
|
/*
|
2012-10-22 05:57:53 -04:00
|
|
|
* Find a valid Lang for current Content. The most recent
|
|
|
|
|
* @param string $ConCategory
|
|
|
|
|
* @param string $ConParent
|
|
|
|
|
* @param string $ConId
|
|
|
|
|
* @return string
|
|
|
|
|
*
|
|
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public static function getDefaultContentLang($ConCategory, $ConParent, $ConId, $destConLang)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
2017-12-04 13:25:35 +00:00
|
|
|
$Criteria = new Criteria('workflow');
|
2012-10-22 05:57:53 -04:00
|
|
|
$Criteria->clearSelectColumns()->clearOrderByColumns();
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$Criteria->addSelectColumn(ContentPeer::CON_CATEGORY);
|
|
|
|
|
$Criteria->addSelectColumn(ContentPeer::CON_PARENT);
|
|
|
|
|
$Criteria->addSelectColumn(ContentPeer::CON_ID);
|
|
|
|
|
$Criteria->addSelectColumn(ContentPeer::CON_LANG);
|
|
|
|
|
$Criteria->addSelectColumn(ContentPeer::CON_VALUE);
|
2012-10-22 05:57:53 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$Criteria->add(ContentPeer::CON_CATEGORY, $ConCategory, CRITERIA::EQUAL);
|
|
|
|
|
$Criteria->add(ContentPeer::CON_PARENT, $ConParent, CRITERIA::EQUAL);
|
|
|
|
|
$Criteria->add(ContentPeer::CON_ID, $ConId, CRITERIA::EQUAL);
|
|
|
|
|
$Criteria->add(ContentPeer::CON_LANG, $destConLang, CRITERIA::NOT_EQUAL);
|
2012-10-22 05:57:53 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$rs = ContentPeer::doSelectRS($Criteria);
|
|
|
|
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2012-10-22 05:57:53 -04:00
|
|
|
$rs->next();
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if (is_array($row = $rs->getRow())) {
|
2012-10-22 05:57:53 -04:00
|
|
|
$defaultLang = $row['CON_LANG'];
|
|
|
|
|
} else {
|
|
|
|
|
$defaultLang = "";
|
|
|
|
|
}
|
|
|
|
|
return ($defaultLang);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-30 09:38:20 -04:00
|
|
|
/*
|
|
|
|
|
* Change the value of all records
|
|
|
|
|
* @param string $ConCategory
|
|
|
|
|
* @param string $ConParent
|
|
|
|
|
* @param string $ConId
|
|
|
|
|
* @param string $ConValue
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public static function updateEqualValue($ConCategory, $ConParent, $ConId, $ConValue)
|
2013-08-30 09:38:20 -04:00
|
|
|
{
|
2013-08-30 12:20:29 -04:00
|
|
|
$con = Propel::getConnection('workflow');
|
|
|
|
|
$c1 = new Criteria('workflow');
|
|
|
|
|
$c1->add(ContentPeer::CON_CATEGORY, $ConCategory);
|
|
|
|
|
$c1->add(ContentPeer::CON_PARENT, $ConParent);
|
|
|
|
|
$c1->add(ContentPeer::CON_ID, $ConId);
|
|
|
|
|
|
|
|
|
|
// update set
|
|
|
|
|
$c2 = new Criteria('workflow');
|
|
|
|
|
$c2->add(ContentPeer::CON_VALUE, $ConValue);
|
|
|
|
|
BasePeer::doUpdate($c1, $c2, $con);
|
2013-08-30 09:38:20 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-19 18:07:17 +00:00
|
|
|
/*
|
|
|
|
|
* Load the content row and the Save automatically the row for the destination language
|
|
|
|
|
* @param string $ConCategory
|
|
|
|
|
* @param string $ConParent
|
|
|
|
|
* @param string $ConId
|
|
|
|
|
* @param string $destConLang
|
|
|
|
|
* @return string
|
|
|
|
|
* if the row doesn't exist, it will be created automatically, even the default 'en' language
|
2012-10-22 05:57:53 -04:00
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public static function autoLoadSave($ConCategory, $ConParent, $ConId, $destConLang)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
2012-10-19 18:07:17 +00:00
|
|
|
//search in 'en' language, the default language
|
2017-12-04 13:25:35 +00:00
|
|
|
$content = ContentPeer::retrieveByPK($ConCategory, $ConParent, $ConId, 'en');
|
2012-10-22 05:57:53 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if ((is_null($content)) || ($content->getConValue() == "")) {
|
|
|
|
|
$differentLang = Content::getDefaultContentLang($ConCategory, $ConParent, $ConId, $destConLang);
|
|
|
|
|
$content = ContentPeer::retrieveByPK($ConCategory, $ConParent, $ConId, $differentLang);
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-19 18:07:17 +00:00
|
|
|
//to do: review if the $destConLang is a valid language/
|
2017-12-04 13:25:35 +00:00
|
|
|
if (is_null($content)) {
|
2012-10-22 05:57:53 -04:00
|
|
|
$ConValue = '';
|
2012-10-19 18:07:17 +00:00
|
|
|
//we dont find any value for this field and language in CONTENT table
|
2012-10-22 05:57:53 -04:00
|
|
|
} else {
|
|
|
|
|
$ConValue = $content->getConValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2017-12-04 13:25:35 +00:00
|
|
|
$con = ContentPeer::retrieveByPK($ConCategory, $ConParent, $ConId, $destConLang);
|
|
|
|
|
if (is_null($con)) {
|
2012-10-22 05:57:53 -04:00
|
|
|
$con = new Content();
|
|
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
$con->setConCategory($ConCategory);
|
|
|
|
|
$con->setConParent($ConParent);
|
|
|
|
|
$con->setConId($ConId);
|
|
|
|
|
$con->setConLang($destConLang);
|
|
|
|
|
$con->setConValue($ConValue);
|
2012-10-22 05:57:53 -04:00
|
|
|
if ($con->validate()) {
|
|
|
|
|
$res = $con->save();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw ($e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ConValue;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 18:07:17 +00:00
|
|
|
/*
|
2012-10-22 05:57:53 -04:00
|
|
|
* Insert a content row
|
|
|
|
|
* @param string $ConCategory
|
|
|
|
|
* @param string $ConParent
|
|
|
|
|
* @param string $ConId
|
|
|
|
|
* @param string $ConLang
|
|
|
|
|
* @param string $ConValue
|
|
|
|
|
* @return variant
|
|
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public static function addContent($ConCategory, $ConParent, $ConId, $ConLang, $ConValue)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
if ($ConLang != 'en') {
|
2017-12-04 13:25:35 +00:00
|
|
|
$baseLangContent = ContentPeer::retrieveByPk($ConCategory, $ConParent, $ConId, 'en');
|
2012-10-22 05:57:53 -04:00
|
|
|
if ($baseLangContent === null) {
|
2017-12-04 13:25:35 +00:00
|
|
|
Content::addContent($ConCategory, $ConParent, $ConId, 'en', $ConValue);
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$con = ContentPeer::retrieveByPK($ConCategory, $ConParent, $ConId, $ConLang);
|
2012-10-22 05:57:53 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if (is_null($con)) {
|
2012-10-22 05:57:53 -04:00
|
|
|
$con = new Content();
|
2017-12-04 13:25:35 +00:00
|
|
|
$con->setConCategory($ConCategory);
|
2013-08-30 12:20:29 -04:00
|
|
|
if ($con->getConParent() != $ConParent) {
|
2017-12-04 13:25:35 +00:00
|
|
|
$con->setConParent($ConParent);
|
2013-08-30 12:20:29 -04:00
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
$con->setConId($ConId);
|
|
|
|
|
$con->setConLang($ConLang);
|
|
|
|
|
$con->setConValue($ConValue);
|
2013-08-30 12:20:29 -04:00
|
|
|
if ($con->validate()) {
|
|
|
|
|
$res = $con->save();
|
|
|
|
|
return $res;
|
|
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
$e = new Exception("Error in addcontent, the row $ConCategory, $ConParent, $ConId, $ConLang is not Valid");
|
2013-08-30 12:20:29 -04:00
|
|
|
throw ($e);
|
|
|
|
|
}
|
2012-10-22 05:57:53 -04:00
|
|
|
} else {
|
|
|
|
|
if ($con->getConParent() == $ConParent && $con->getConCategory() == $ConCategory && $con->getConValue() == $ConValue && $con->getConLang() == $ConLang && $con->getConId() == $ConId) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
Content::updateEqualValue($ConCategory, $ConParent, $ConId, $ConValue);
|
2013-08-30 12:20:29 -04:00
|
|
|
return true;
|
2012-10-22 05:57:53 -04:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw ($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 18:07:17 +00:00
|
|
|
/*
|
2012-10-22 05:57:53 -04:00
|
|
|
* Insert a content row
|
|
|
|
|
* @param string $ConCategory
|
|
|
|
|
* @param string $ConParent
|
|
|
|
|
* @param string $ConId
|
|
|
|
|
* @param string $ConLang
|
|
|
|
|
* @param string $ConValue
|
|
|
|
|
* @return variant
|
|
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public function insertContent($ConCategory, $ConParent, $ConId, $ConLang, $ConValue)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$con = new Content();
|
2017-12-04 13:25:35 +00:00
|
|
|
$con->setConCategory($ConCategory);
|
|
|
|
|
$con->setConParent($ConParent);
|
|
|
|
|
$con->setConId($ConId);
|
|
|
|
|
$con->setConLang($ConLang);
|
|
|
|
|
$con->setConValue($ConValue);
|
2012-10-22 05:57:53 -04:00
|
|
|
if ($con->validate()) {
|
|
|
|
|
$res = $con->save();
|
|
|
|
|
return $res;
|
|
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
$e = new Exception("Error in addcontent, the row $ConCategory, $ConParent, $ConId, $ConLang is not Valid");
|
2012-10-22 05:57:53 -04:00
|
|
|
throw ($e);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw ($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 18:07:17 +00:00
|
|
|
/*
|
2012-10-22 05:57:53 -04:00
|
|
|
* remove a content row
|
|
|
|
|
* @param string $ConCategory
|
|
|
|
|
* @param string $ConParent
|
|
|
|
|
* @param string $ConId
|
|
|
|
|
* @param string $ConLang
|
|
|
|
|
* @param string $ConValue
|
|
|
|
|
* @return variant
|
|
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public static function removeContent($ConCategory, $ConParent, $ConId)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$c = new Criteria();
|
2017-12-04 13:25:35 +00:00
|
|
|
$c->add(ContentPeer::CON_CATEGORY, $ConCategory);
|
|
|
|
|
$c->add(ContentPeer::CON_PARENT, $ConParent);
|
|
|
|
|
$c->add(ContentPeer::CON_ID, $ConId);
|
|
|
|
|
$result = ContentPeer::doSelectRS($c);
|
2012-10-22 05:57:53 -04:00
|
|
|
$result->next();
|
|
|
|
|
$row = $result->getRow();
|
2017-12-04 13:25:35 +00:00
|
|
|
while (is_array($row)) {
|
|
|
|
|
ContentPeer::doDelete(array($ConCategory,$ConParent,$ConId,$row[3]));
|
2012-10-22 05:57:53 -04:00
|
|
|
$result->next();
|
|
|
|
|
$row = $result->getRow();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw ($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-19 18:07:17 +00:00
|
|
|
/*
|
2012-10-22 05:57:53 -04:00
|
|
|
* Reasons if the record already exists
|
|
|
|
|
*
|
|
|
|
|
* @param string $ConCategory
|
|
|
|
|
* @param string $ConParent
|
|
|
|
|
* @param string $ConId
|
|
|
|
|
* @param string $ConLang
|
|
|
|
|
* @param string $ConValue
|
|
|
|
|
* @return boolean true or false
|
|
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public function Exists($ConCategory, $ConParent, $ConId, $ConLang)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2017-12-04 13:25:35 +00:00
|
|
|
$oPro = ContentPeer::retrieveByPk($ConCategory, $ConParent, $ConId, $ConLang);
|
|
|
|
|
if (is_object($oPro) && get_class($oPro) == 'Content') {
|
2012-10-22 05:57:53 -04:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 10:15:20 -04:00
|
|
|
/*
|
|
|
|
|
* Regenerate Table Content
|
|
|
|
|
*
|
|
|
|
|
* @param array $langs
|
2012-10-22 05:57:53 -04:00
|
|
|
*/
|
2017-10-06 17:21:21 -04:00
|
|
|
public function regenerateContent ($langs, $workSpace = null)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
2017-10-06 17:21:21 -04:00
|
|
|
if ($workSpace === null) {
|
2017-10-10 12:33:25 -04:00
|
|
|
$workSpace = config("system.workspace");
|
2017-10-06 17:21:21 -04:00
|
|
|
}
|
2012-09-26 10:15:20 -04:00
|
|
|
//Search the language
|
2017-12-04 13:25:35 +00:00
|
|
|
$key = array_search('en', $langs);
|
2012-10-22 05:57:53 -04:00
|
|
|
if ($key === false) {
|
2017-12-04 13:25:35 +00:00
|
|
|
$key = array_search(SYS_LANG, $langs);
|
2012-10-22 05:57:53 -04:00
|
|
|
if ($key === false) {
|
|
|
|
|
$key = '0';
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->langsAsoc = [];
|
2012-10-22 05:57:53 -04:00
|
|
|
foreach ($langs as $key => $value) {
|
|
|
|
|
$this->langsAsoc[$value] = $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->langs = $langs;
|
|
|
|
|
$this->rowsProcessed = 0;
|
|
|
|
|
$this->rowsInserted = 0;
|
|
|
|
|
$this->rowsUnchanged = 0;
|
|
|
|
|
$this->rowsClustered = 0;
|
|
|
|
|
|
2012-10-10 17:07:14 -04:00
|
|
|
//Creating table CONTENT_BACKUP
|
2017-12-04 13:25:35 +00:00
|
|
|
$connection = Propel::getConnection('workflow');
|
|
|
|
|
$oStatement = $connection->prepareStatement("CREATE TABLE IF NOT EXISTS `CONTENT_BACKUP` (
|
2012-10-10 17:07:14 -04:00
|
|
|
`CON_CATEGORY` VARCHAR(30) default '' NOT NULL,
|
|
|
|
|
`CON_PARENT` VARCHAR(32) default '' NOT NULL,
|
|
|
|
|
`CON_ID` VARCHAR(100) default '' NOT NULL,
|
|
|
|
|
`CON_LANG` VARCHAR(10) default '' NOT NULL,
|
|
|
|
|
`CON_VALUE` MEDIUMTEXT NOT NULL,
|
|
|
|
|
CONSTRAINT CONTENT_BACKUP_PK PRIMARY KEY (CON_CATEGORY,CON_PARENT,CON_ID,CON_LANG)
|
2017-12-04 13:25:35 +00:00
|
|
|
)Engine=InnoDB DEFAULT CHARSET='utf8' COMMENT='Table for add content';");
|
2012-10-22 05:57:53 -04:00
|
|
|
$oStatement->executeQuery();
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$sql = ' SELECT DISTINCT CON_LANG FROM CONTENT ';
|
2012-11-30 09:40:58 -04:00
|
|
|
$stmt = $connection->createStatement();
|
2017-12-04 13:25:35 +00:00
|
|
|
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
2012-10-22 05:57:53 -04:00
|
|
|
while ($rs->next()) {
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
$language = $row['CON_LANG'];
|
2017-12-04 13:25:35 +00:00
|
|
|
if (array_search($row['CON_LANG'], $langs) === false) {
|
|
|
|
|
Content::removeLanguageContent($row['CON_LANG']);
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-26 10:15:20 -04:00
|
|
|
$sql = " SELECT CON_ID, CON_CATEGORY, CON_LANG, CON_PARENT, CON_VALUE
|
|
|
|
|
FROM CONTENT
|
2012-10-22 05:57:53 -04:00
|
|
|
ORDER BY CON_ID, CON_CATEGORY, CON_PARENT, CON_LANG";
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$workSpace = new WorkspaceTools($workSpace);
|
2012-10-22 05:57:53 -04:00
|
|
|
$workSpace->getDBInfo();
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$mysqli = new mysqli($workSpace->dbHost, $workSpace->dbUser, $workSpace->dbPass, $workSpace->dbName) or die("Could not connect");
|
2012-10-22 05:57:53 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$mysqli->query( 'SET NAMES "utf8";');
|
|
|
|
|
$mysqli->query( 'SET FOREIGN_KEY_CHECKS=0;');
|
|
|
|
|
$mysqli->query( 'SET OPTION SQL_BIG_SELECTS=1');
|
|
|
|
|
$result = $mysqli->query( $sql, MYSQLI_USE_RESULT);
|
|
|
|
|
$list = [];
|
|
|
|
|
$default = [];
|
|
|
|
|
$sw = array('CON_ID' => '','CON_CATEGORY' => '','CON_PARENT' => ''
|
2012-10-22 05:57:53 -04:00
|
|
|
);
|
2017-12-04 13:25:35 +00:00
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
|
|
|
if ($sw['CON_ID'] === $row['CON_ID'] && $sw['CON_CATEGORY'] === $row['CON_CATEGORY'] && $sw['CON_PARENT'] === $row['CON_PARENT']) {
|
2012-10-22 05:57:53 -04:00
|
|
|
$list[] = $row;
|
|
|
|
|
} else {
|
|
|
|
|
$this->rowsClustered ++;
|
2017-12-04 13:25:35 +00:00
|
|
|
if (count($langs) !== count($list)) {
|
|
|
|
|
$this->checkLanguage($list, $default);
|
2012-10-22 05:57:53 -04:00
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->rowsUnchanged += count($langs);
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
$sw = [];
|
2012-10-22 05:57:53 -04:00
|
|
|
$sw['CON_ID'] = $row['CON_ID'];
|
|
|
|
|
$sw['CON_CATEGORY'] = $row['CON_CATEGORY'];
|
|
|
|
|
$sw['CON_LANG'] = $row['CON_LANG'];
|
|
|
|
|
$sw['CON_PARENT'] = $row['CON_PARENT'];
|
2017-12-04 13:25:35 +00:00
|
|
|
unset($list);
|
|
|
|
|
unset($default);
|
|
|
|
|
$list = [];
|
|
|
|
|
$default = [];
|
2012-10-22 05:57:53 -04:00
|
|
|
$list[] = $row;
|
|
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
if ($sw['CON_LANG'] === $langs[$key]) {
|
2012-10-22 05:57:53 -04:00
|
|
|
$default = $row;
|
|
|
|
|
}
|
|
|
|
|
$this->rowsProcessed ++;
|
|
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
if (count($langs) !== count($list)) {
|
|
|
|
|
$this->checkLanguage($list, $default);
|
2012-10-22 05:57:53 -04:00
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->rowsUnchanged += count($langs);
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
mysqli_free_result($result);
|
2012-10-22 05:57:53 -04:00
|
|
|
$total = $this->rowsProcessed + $this->rowsInserted;
|
2012-11-30 09:40:58 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$result->close();
|
|
|
|
|
|
|
|
|
|
$statement = $connection->prepareStatement("REPLACE INTO CONTENT
|
2012-10-10 17:07:14 -04:00
|
|
|
SELECT CON_CATEGORY, CON_PARENT, CON_ID , CON_LANG, CON_VALUE
|
2017-12-04 13:25:35 +00:00
|
|
|
FROM CONTENT_BACKUP");
|
2012-10-22 05:57:53 -04:00
|
|
|
$statement->executeQuery();
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$statement = $connection->prepareStatement("DROP TABLE CONTENT_BACKUP");
|
2012-10-22 05:57:53 -04:00
|
|
|
$statement->executeQuery();
|
|
|
|
|
|
2012-12-17 14:37:46 -04:00
|
|
|
//close connection
|
|
|
|
|
$sql = "SELECT * FROM information_schema.processlist WHERE command = 'Sleep' and user = SUBSTRING_INDEX(USER(),'@',1) and db = DATABASE() ORDER BY id;";
|
|
|
|
|
$stmt = $connection->createStatement();
|
2017-12-04 13:25:35 +00:00
|
|
|
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
2012-12-17 14:37:46 -04:00
|
|
|
while ($rs->next()) {
|
|
|
|
|
$row = $rs->getRow();
|
2017-12-04 13:25:35 +00:00
|
|
|
$oStatement = $connection->prepareStatement("kill ". $row['ID']);
|
2012-12-17 14:37:46 -04:00
|
|
|
$oStatement->executeQuery();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if (! isset($_SERVER['SERVER_NAME'])) {
|
|
|
|
|
CLI::logging("Rows Processed ---> $this->rowsProcessed ..... \n");
|
|
|
|
|
CLI::logging("Rows Clustered ---> $this->rowsClustered ..... \n");
|
|
|
|
|
CLI::logging("Rows Unchanged ---> $this->rowsUnchanged ..... \n");
|
|
|
|
|
CLI::logging("Rows Inserted ---> $this->rowsInserted ..... \n");
|
|
|
|
|
CLI::logging("Rows Total ---> $total ..... \n");
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
public function checkLanguage($content, $default)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
2017-12-04 13:25:35 +00:00
|
|
|
if (count($content) > 0) {
|
2012-10-22 05:57:53 -04:00
|
|
|
$langs = $this->langs;
|
|
|
|
|
$langsAsoc = $this->langsAsoc;
|
2012-09-26 10:15:20 -04:00
|
|
|
//Element default
|
2017-12-04 13:25:35 +00:00
|
|
|
$default = (count($default) > 0) ? $default : $content[0];
|
2012-10-22 05:57:53 -04:00
|
|
|
foreach ($content as $key => $value) {
|
2017-12-04 13:25:35 +00:00
|
|
|
unset($langsAsoc[$value['CON_LANG']]);
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
|
|
|
|
foreach ($langsAsoc as $key => $value) {
|
|
|
|
|
$this->rowsInserted ++;
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->fastInsertContent($default['CON_CATEGORY'], $default['CON_PARENT'], $default['CON_ID'], $value, $default['CON_VALUE']);
|
2012-10-22 05:57:53 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
public function fastInsertContent($ConCategory, $ConParent, $ConId, $ConLang, $ConValue)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
2017-12-04 13:25:35 +00:00
|
|
|
$connection = Propel::getConnection('workflow');
|
|
|
|
|
$ConValue = mysqli_real_escape_string($connection, $ConValue);
|
|
|
|
|
$statement = $connection->prepareStatement("INSERT INTO CONTENT_BACKUP (
|
2012-10-10 17:07:14 -04:00
|
|
|
CON_CATEGORY, CON_PARENT, CON_ID , CON_LANG, CON_VALUE)
|
2017-12-04 13:25:35 +00:00
|
|
|
VALUES ('$ConCategory', '$ConParent', '$ConId', '$ConLang', '$ConValue');");
|
2012-10-22 05:57:53 -04:00
|
|
|
$statement->executeQuery();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
public function removeLanguageContent($lanId)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$c = new Criteria();
|
2017-12-04 13:25:35 +00:00
|
|
|
$c->addSelectColumn(ContentPeer::CON_CATEGORY);
|
|
|
|
|
$c->addSelectColumn(ContentPeer::CON_PARENT);
|
|
|
|
|
$c->addSelectColumn(ContentPeer::CON_ID);
|
|
|
|
|
$c->addSelectColumn(ContentPeer::CON_LANG);
|
2012-10-22 05:57:53 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$c->add(ContentPeer::CON_LANG, $lanId);
|
2012-10-22 05:57:53 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$result = ContentPeer::doSelectRS($c);
|
|
|
|
|
$result->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2012-10-22 05:57:53 -04:00
|
|
|
$result->next();
|
|
|
|
|
$row = $result->getRow();
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
while (is_array($row)) {
|
|
|
|
|
$content = ContentPeer::retrieveByPK($row['CON_CATEGORY'], $row['CON_PARENT'], $row['CON_ID'], $lanId);
|
2012-10-22 05:57:53 -04:00
|
|
|
|
|
|
|
|
if ($content !== null) {
|
|
|
|
|
$content->delete();
|
|
|
|
|
}
|
|
|
|
|
$result->next();
|
|
|
|
|
$row = $result->getRow();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw ($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
/**
|
|
|
|
|
* Gets all Role Names by Role
|
|
|
|
|
*
|
|
|
|
|
* @param string $sys_lang language
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getAllContentsByRole($sys_lang = SYS_LANG)
|
2012-10-22 05:57:53 -04:00
|
|
|
{
|
2017-12-04 13:25:35 +00:00
|
|
|
if (! isset($sys_lang)) {
|
2012-10-22 05:57:53 -04:00
|
|
|
$sys_lang = 'en';
|
|
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
$oCriteria = new Criteria('workflow');
|
2012-10-22 05:57:53 -04:00
|
|
|
$oCriteria->clearSelectColumns();
|
2017-12-04 13:25:35 +00:00
|
|
|
$oCriteria->addSelectColumn(ContentPeer::CON_ID);
|
|
|
|
|
$oCriteria->addAsColumn('ROL_NAME', ContentPeer::CON_VALUE);
|
|
|
|
|
$oCriteria->add(ContentPeer::CON_CATEGORY, 'ROL_NAME');
|
|
|
|
|
$oCriteria->add(ContentPeer::CON_LANG, $sys_lang);
|
|
|
|
|
$oDataset = ContentPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$aRoles = [];
|
2012-10-22 05:57:53 -04:00
|
|
|
while ($oDataset->next()) {
|
|
|
|
|
$xRow = $oDataset->getRow();
|
|
|
|
|
$aRoles[$xRow['CON_ID']] = $xRow['ROL_NAME'];
|
|
|
|
|
}
|
|
|
|
|
return $aRoles;
|
|
|
|
|
}
|
|
|
|
|
}
|