Skip to content

Commit

Permalink
FEATURE / db updates without POST (#597)
Browse files Browse the repository at this point in the history
* DB patch will run on any request (not just POST anymore)

* Core changes to make module updating possible on any request (not just POST)
  • Loading branch information
jegelstaff authored Nov 17, 2024
1 parent 5329d89 commit adb8389
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 108 deletions.
12 changes: 6 additions & 6 deletions libraries/icms/config/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ public function &getConfig($id, $withoptions = false) {
* @param object &$config reference to the {@link icms_config_Item_Object}
* @return true|false if inserting config succeeded or not
*/
public function insertConfig(&$config) {
if (!$this->_cHandler->insert($config)) {
public function insertConfig(&$config, $force=false) {
if (!$this->_cHandler->insert($config, $force)) {
return false;
}
$options =& $config->getConfOptions();
$count = count($options);
$conf_id = $config->getVar('conf_id');
for ( $i = 0; $i < $count; $i++) {
$options[$i]->setVar('conf_id', $conf_id);
if (!$this->_oHandler->insert($options[$i])) {
if (!$this->_oHandler->insert($options[$i], $force)) {
foreach ( $options[$i]->getErrors() as $msg) {
$config->setErrors($msg);
}
Expand All @@ -149,8 +149,8 @@ public function insertConfig(&$config) {
* @param object &$config reference to a {@link icms_config_Item_Object}
* @return true|false if deleting config item succeeded or not
*/
public function deleteConfig(&$config) {
if (!$this->_cHandler->delete($config)) {
public function deleteConfig(&$config, $force=false) {
if (!$this->_cHandler->delete($config, $force)) {
return false;
}
$options =& $config->getConfOptions();
Expand All @@ -161,7 +161,7 @@ public function deleteConfig(&$config) {
}
if (is_array($options) && $count > 0) {
for ( $i = 0; $i < $count; $i++) {
$this->_oHandler->delete($options[$i]);
$this->_oHandler->delete($options[$i], $force);
}
}
if (!empty($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')])) {
Expand Down
24 changes: 18 additions & 6 deletions libraries/icms/config/item/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function &get($id) {
* @param object &$config {@link icms_config_Item_Object} object
* @return mixed FALSE on fail.
*/
public function insert(&$config) {
public function insert(&$config, $force=true) {
/* As of PHP5.3.0, is_a() is no longer deprecated, no need to replace this */
if (!is_a($config, 'icms_config_Item_Object')) {
return false;
Expand Down Expand Up @@ -180,8 +180,14 @@ public function insert(&$config) {
(int) $conf_id
);
}
if (!$result = $this->db->query($sql)) {
return false;
if($force) {
if (!$result = $this->db->queryF($sql)) {
return false;
}
} else {
if (!$result = $this->db->query($sql)) {
return false;
}
}
if (empty($conf_id)) {
$conf_id = $this->db->getInsertId();
Expand All @@ -196,7 +202,7 @@ public function insert(&$config) {
* @param object &$config Config to delete
* @return bool Successful?
*/
public function delete(&$config) {
public function delete(&$config, $force=false) {
/* As of PHP5.3.0, is_as() is no longer deprecated, there is no need to replace it */
if (!is_a($config, 'icms_config_Item_Object')) {
return false;
Expand All @@ -205,8 +211,14 @@ public function delete(&$config) {
"DELETE FROM %s WHERE conf_id = '%u'",
$this->db->prefix('config'), (int) $config->getVar('conf_id')
);
if (!$result = $this->db->query($sql)) {
return false;
if($force) {
if (!$result = $this->db->queryF($sql)) {
return false;
}
} else {
if (!$result = $this->db->query($sql)) {
return false;
}
}
return true;
}
Expand Down
24 changes: 18 additions & 6 deletions libraries/icms/config/option/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function &get($id) {
* @param object &$confoption reference to a {@link icms_config_option_Object}
* @return bool TRUE if successfull.
*/
public function insert(&$confoption) {
public function insert(&$confoption, $force=false) {
/* As of PHP5.3.0, is_a() is no longer deprecated, no need to replace it */
if (!is_a($confoption, 'icms_config_option_Object')) {
return false;
Expand Down Expand Up @@ -106,8 +106,14 @@ public function insert(&$confoption) {
(int) ($confop_id)
);
}
if (!$result = $this->db->query($sql)) {
return false;
if($force) {
if (!$result = $this->db->queryF($sql)) {
return false;
}
} else {
if (!$result = $this->db->query($sql)) {
return false;
}
}
if (empty($confop_id)) {
$confop_id = $this->db->getInsertId();
Expand All @@ -122,7 +128,7 @@ public function insert(&$confoption) {
* @param object &$confoption reference to a {@link icms_config_option_Object}
* @return bool TRUE if successful
*/
public function delete(&$confoption) {
public function delete(&$confoption, $force=false) {
/* As of PHP5.3.0, is_a() is no longer deprecated, no need to replace it */
if (!is_a($confoption, 'icms_config_option_Object')) {
return false;
Expand All @@ -132,8 +138,14 @@ public function delete(&$confoption) {
$this->db->prefix('configoption'),
(int) ($confoption->getVar('confop_id'))
);
if (!$result = $this->db->query($sql)) {
return false;
if($force) {
if (!$result = $this->db->queryF($sql)) {
return false;
}
} else {
if (!$result = $this->db->query($sql)) {
return false;
}
}
return true;
}
Expand Down
12 changes: 9 additions & 3 deletions libraries/icms/member/groupperm/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function &get($id) {
* @return bool TRUE on success
*
*/
public function insert(&$perm) {
public function insert(&$perm, $force=false) {
/* As of PHP5.3.0, is_a() is no longer deprecated and there is no need to replace it */
if (!is_a($perm, 'icms_member_groupperm_Object')) {
return false;
Expand Down Expand Up @@ -110,8 +110,14 @@ public function insert(&$perm) {
(int) $gperm_id
);
}
if (!$result = icms::$xoopsDB->query($sql)) {
return false;
if($force) {
if (!$result = $this->db->queryF($sql)) {
return false;
}
} else {
if (!$result = $this->db->query($sql)) {
return false;
}
}
if (empty($gperm_id)) {
$gperm_id = icms::$xoopsDB->getInsertId();
Expand Down
12 changes: 10 additions & 2 deletions libraries/icms/module/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private function loadConfig($module) {
* @param object &$module reference to a {@link icms_module_Object}
* @return bool
*/
public function insert(&$module) {
public function insert(&$module, $force=false) {
if (get_class($module) != 'icms_module_Object') return FALSE;
if (!$module->isDirty()) return TRUE;
if (!$module->cleanVars()) return FALSE;
Expand Down Expand Up @@ -178,7 +178,15 @@ public function insert(&$module) {
$sql .= " WHERE " . $whereclause;
}

if (!$result = $this->db->query($sql)) return FALSE;
if($force) {
if (!$result = $this->db->queryF($sql)) {
return false;
}
} else {
if (!$result = $this->db->query($sql)) {
return false;
}
}
if ($module->isNew()) { $module->assignVar('mid', $this->db->getInsertId()); }
if (!empty($this->_cachedModule[$module->getVar('dirname')])) {
unset($this->_cachedModule[$module->getVar('dirname')]);
Expand Down
64 changes: 49 additions & 15 deletions libraries/icms/view/template/file/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function loadSource(&$tplfile) {
* @param object $tplfile {@link icms_view_template_file_Object} object of the template file to load
* @return bool TRUE on success, FALSE if fail
**/
public function insert(&$tplfile) {
public function insert(&$tplfile, $force=false) {
/* As of PHP5.3.0, is_a() is no longer deprecated */
if (!is_a($tplfile, 'icms_view_template_file_Object')) {
return false;
Expand Down Expand Up @@ -133,8 +133,15 @@ public function insert(&$tplfile) {
(int) $tpl_lastimported,
$this->db->quoteString($tpl_type)
);
if (!$result = $this->db->query($sql)) {
return false;

if($force) {
if (!$result = $this->db->queryF($sql)) {
return false;
}
} else {
if (!$result = $this->db->query($sql)) {
return false;
}
}
if (empty($tpl_id)) {
$tpl_id = $this->db->getInsertId();
Expand All @@ -146,11 +153,20 @@ public function insert(&$tplfile) {
(int) $tpl_id,
$this->db->quoteString($tpl_source)
);
if (!$result = $this->db->query($sql)) {
$this->db->query(sprintf("DELETE FROM %s WHERE tpl_id = '%u'",
$this->db->prefix('tplfile'), (int) $tpl_id)
);
return false;
if($force) {
if (!$result = $this->db->queryF($sql)) {
$this->db->queryF(sprintf("DELETE FROM %s WHERE tpl_id = '%u'",
$this->db->prefix('tplfile'), (int) $tpl_id)
);
return false;
}
} else {
if (!$result = $this->db->query($sql)) {
$this->db->query(sprintf("DELETE FROM %s WHERE tpl_id = '%u'",
$this->db->prefix('tplfile'), (int) $tpl_id)
);
return false;
}
}
}
$tplfile->assignVar('tpl_id', $tpl_id);
Expand All @@ -165,17 +181,29 @@ public function insert(&$tplfile) {
(int) $tpl_lastmodified,
(int) $tpl_id
);
if (!$result = $this->db->query($sql)) {
return false;
if($force) {
if (!$result = $this->db->queryF($sql)) {
return false;
}
} else {
if (!$result = $this->db->query($sql)) {
return false;
}
}
if (isset($tpl_source) && $tpl_source != '') {
$sql = sprintf("UPDATE %s SET tpl_source = %s WHERE tpl_id = '%u'",
$this->db->prefix('tplsource'),
$this->db->quoteString($tpl_source),
(int) $tpl_id
);
if (!$result = $this->db->query($sql)) {
return false;
if($force) {
if (!$result = $this->db->queryF($sql)) {
return false;
}
} else {
if (!$result = $this->db->query($sql)) {
return false;
}
}
}
}
Expand Down Expand Up @@ -223,15 +251,21 @@ public function forceUpdate(&$tplfile) {
* @param object $tplfile {@link icms_view_template_file_Object} object of the template file to load
* @return bool TRUE on success, FALSE if fail
**/
public function delete(&$tplfile) {
public function delete(&$tplfile, $force=false) {
/* As of PHP5.3.0, is_a() is no longer deprecated */
if (!is_a($tplfile, 'icms_view_template_file_Object')) {
return false;
}
$id = (int) ($tplfile->getVar('tpl_id'));
$sql = sprintf("DELETE FROM %s WHERE tpl_id = '%u'", $this->db->prefix('tplfile'), $id);
if (!$result = $this->db->query($sql)) {
return false;
if($force) {
if (!$result = $this->db->queryF($sql)) {
return false;
}
} else {
if (!$result = $this->db->query($sql)) {
return false;
}
}
$sql = sprintf("DELETE FROM %s WHERE tpl_id = '%u'", $this->db->prefix('tplsource'), $id);
$this->db->query($sql);
Expand Down
Loading

0 comments on commit adb8389

Please sign in to comment.