Skip to content

Commit

Permalink
Add a new setting - database query limit. This new setting allow the …
Browse files Browse the repository at this point in the history
…user to change the query limit from a database update or synchronization. See #163
  • Loading branch information
stefanheimes committed Oct 24, 2013
1 parent c635b5e commit 64faeea
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 21 deletions.
15 changes: 11 additions & 4 deletions system/modules/syncCto/SyncCtoDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,21 @@ protected function checkRAM(XMLWriter $objXml, $objGzFile)
* @param bool $booTempFolder Should the tmp folde used instead of backupfolder
* @return void
*/
public function runDump($mixTables, $booTempFolder, $booOnlyMachine = false)
public function runDump($mixTables, $booTempFolder, $booOnlyMachine = true)
{
// Set time limit to unlimited
set_time_limit(0);

// Set limit for db query. Ticket #163
if ($GLOBALS['TL_CONFIG']['syncCto_custom_settings'] == true && intval($GLOBALS['TL_CONFIG']['syncCto_db_query_limt']) > 0)
{
$intElementsPerRequest = intval($GLOBALS['TL_CONFIG']['syncCto_db_query_limt']);
}
else
{
$intElementsPerRequest = 500;
}

// Add to the backup array all tables
if (is_array($mixTables))
{
Expand Down Expand Up @@ -415,8 +425,6 @@ public function runDump($mixTables, $booTempFolder, $booOnlyMachine = false)
$arrFieldMeta[$value["name"]] = $value;
}

$intElementsPerRequest = 500;

$objXml->startElement('table');
$objXml->writeAttribute('name', $TableName);

Expand Down Expand Up @@ -606,7 +614,6 @@ public function runDump($mixTables, $booTempFolder, $booOnlyMachine = false)
$arrFieldMeta[$value["name"]] = $value;
}

$intElementsPerRequest = 500;
$booFirstEntry = true;

for ($i = 0; true; $i++)
Expand Down
84 changes: 69 additions & 15 deletions system/modules/syncCto/dca/tl_syncCto_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
),
'subpalettes' => array
(
'syncCto_custom_settings' => 'syncCto_wait_timeout,syncCto_interactive_timeout',
'syncCto_custom_settings' => 'syncCto_wait_timeout,syncCto_interactive_timeout,syncCto_db_query_limt',
),
// Fields
'fields' => array(
Expand Down Expand Up @@ -125,30 +125,52 @@
'exclude' => true,
'eval' => array('submitOnChange' => true),
),
'syncCto_wait_timeout' => array
'syncCto_wait_timeout' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_syncCto_settings']['wait_timeout'],
'inputType' => 'text',
'exclude' => true,
'load_callback' => array(array('tl_syncCto_settings', 'checkDefaulTimeoutValue')),
'eval' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_syncCto_settings']['wait_timeout'],
'inputType' => 'text',
'exclude' => true,
'eval' => array('tl_class' => 'w50'),
'tl_class' => 'w50',
'rgxp' => 'digit'
),
),
'syncCto_interactive_timeout' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_syncCto_settings']['interactive_timeout'],
'inputType' => 'text',
'exclude' => true,
'load_callback' => array(array('tl_syncCto_settings', 'checkDefaulTimeoutValue')),
'eval' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_syncCto_settings']['interactive_timeout'],
'inputType' => 'text',
'exclude' => true,
'eval' => array('tl_class' => 'w50'),
'tl_class' => 'w50',
'rgxp' => 'digit'
),
),
'syncCto_auto_db_updater' => array
'syncCto_db_query_limt' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_syncCto_settings']['db_query_limt'],
'inputType' => 'text',
'exclude' => true,
'load_callback' => array(array('tl_syncCto_settings', 'checkDefaulQueryValue')),
'eval' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_syncCto_settings']['syncCto_auto_db_updater'],
'tl_class' => 'w50',
'rgxp' => 'digit'
),
),
'syncCto_auto_db_updater' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_syncCto_settings']['auto_db_updater'],
'inputType' => 'checkbox',
'exclude' => true,
'eval' => array
(
'tl_class' => 'clr',
(
'tl_class' => 'clr',
'multiple' => true,
'disabled' => SyncCtoHelper::isContao2() ? false : true,
'disabled' => SyncCtoHelper::isContao2() ? false : true,
),
'reference' => $GLOBALS['TL_LANG']['tl_syncCto_settings'],
'options' => array(
Expand Down Expand Up @@ -302,5 +324,37 @@ public function loadTablesHidden($strValue)
{
return $this->objSyncCtoHelper->getTablesHidden();
}

/**
* Check if we have a valid value for the timeout.
*
* @param mixed $strValue Value from DC.
* @return int Default Value or the value from DC.
*/
public function checkDefaulTimeoutValue($strValue)
{
if(empty($strValue) || $strValue < 1)
{
return 28000;
}

return $strValue;
}

/**
* Check if we have a valid value for the query limit.
*
* @param mixed $strValue Value from DC.
* @return int Default Value or the value from DC.
*/
public function checkDefaulQueryValue($strValue)
{
if(empty($strValue) || $strValue < 1)
{
return 500;
}

return $strValue;
}

}
3 changes: 2 additions & 1 deletion system/modules/syncCto/languages/de/tl_syncCto_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
$GLOBALS['TL_LANG']['tl_syncCto_settings']['custom_settings'] = array('Experten-Einstellungen aktivieren', 'Klicken Sie hier, wenn Sie wissen was Sie tun.');
$GLOBALS['TL_LANG']['tl_syncCto_settings']['wait_timeout'] = array('"wait_timeout" konfigurieren', 'Mehr Informationen: http://goo.gl/rC5Y4');
$GLOBALS['TL_LANG']['tl_syncCto_settings']['interactive_timeout'] = array('"interactive_timeout" konfigurieren', 'Mehr Informationen: http://goo.gl/VHxRK');
$GLOBALS['TL_LANG']['tl_syncCto_settings']['syncCto_auto_db_updater'] = array('Automatische Aktualisierung der Datenbank', 'Hier können Sie auswählen, welche Aktion der DB Update nach einer Synchronisation ausführen soll.');
$GLOBALS['TL_LANG']['tl_syncCto_settings']['db_query_limt'] = array('Datenbank Abfragelimit', 'Hier können Sie festlegen wieviele Datensätze auf einmal aus der DB geladen werden. Korrigieren Sie das Limit nach unten, wenn ein "500 Server Error" beim DB-Backup/Synchronisation entsteht.');
$GLOBALS['TL_LANG']['tl_syncCto_settings']['auto_db_updater'] = array('Automatische Aktualisierung der Datenbank', 'Hier können Sie auswählen, welche Aktion der DB Update nach einer Synchronisation ausführen soll.');

/**
* Updater
Expand Down
3 changes: 2 additions & 1 deletion system/modules/syncCto/languages/en/tl_syncCto_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
$GLOBALS['TL_LANG']['tl_syncCto_settings']['custom_settings'] = array('Activate expert settings', 'Click here if you know what you are doing.');
$GLOBALS['TL_LANG']['tl_syncCto_settings']['wait_timeout'] = array('Configure "wait_timeout"', 'More informationen: http://goo.gl/rC5Y4');
$GLOBALS['TL_LANG']['tl_syncCto_settings']['interactive_timeout'] = array('Configure "interactive_timeout"', 'More informationen: http://goo.gl/VHxRK');
$GLOBALS['TL_LANG']['tl_syncCto_settings']['syncCto_auto_db_updater'] = array('Automatic updating of the database', 'Here you can choose the actions for the automatic database update, after the synchronization is finished.');
$GLOBALS['TL_LANG']['tl_syncCto_settings']['db_query_limt'] = array('Database query limit', 'Here you can define how many records will be loaded from the database at once. If you encounter a "500 server error" when synchronizing the database, you should set the limit to a lower value.');
$GLOBALS['TL_LANG']['tl_syncCto_settings']['auto_db_updater'] = array('Automatic updating of the database', 'Here you can choose the actions for the automatic database update, after the synchronization is finished.');

/**
* Updater
Expand Down

0 comments on commit 64faeea

Please sign in to comment.