check function pass to setCallback() and addCallback() is callable, remove createDump()

This commit is contained in:
Uwe Steinmann 2021-09-17 19:00:06 +02:00
parent 59c16b3ce4
commit 2789e017eb

View File

@ -3292,62 +3292,55 @@ class SeedDMS_Core_DMS {
/**
* Set a callback function
*
* The function passed in $func must be a callable and $name may not be empty.
*
* Setting a callback with the method will remove all priorly set callbacks.
*
* @param string $name internal name of callback
* @param mixed $func function name as expected by {call_user_method}
* @param mixed $params parameter passed as the first argument to the
* callback
* @return bool true if adding the callback succeeds otherwise false
*/
function setCallback($name, $func, $params=null) { /* {{{ */
if($name && $func)
if($name && $func && is_callable($func)) {
$this->callbacks[$name] = array(array($func, $params));
return true;
} else {
return false;
}
} /* }}} */
/**
* Add a callback function
*
* The function passed in $func must be a callable and $name may not be empty.
*
* @param string $name internal name of callback
* @param mixed $func function name as expected by {call_user_method}
* @param mixed $params parameter passed as the first argument to the
* callback
* @return bool true if adding the callback succeeds otherwise false
*/
function addCallback($name, $func, $params=null) { /* {{{ */
if($name && $func)
if($name && $func && is_callable($func)) {
$this->callbacks[$name][] = array($func, $params);
return true;
} else {
return false;
}
} /* }}} */
/**
* Create an sql dump of the complete database
* Check if a callback with the given has been set
*
* @param string $filename name of dump file
* @return bool
* @param string $name internal name of callback
* @return bool true a callback exists otherwise false
*/
function createDump($filename) { /* {{{ */
$h = fopen($filename, "w");
if(!$h)
return false;
$tables = $this->db->TableList('TABLES');
foreach($tables as $table) {
$query = "SELECT * FROM `".$table."`";
$records = $this->db->getResultArray($query);
fwrite($h,"\n-- TABLE: ".$table."--\n\n");
foreach($records as $record) {
$values="";
$i = 1;
foreach ($record as $column) {
if (is_numeric($column)) $values .= $column;
else $values .= $this->db->qstr($column);
if ($i<(count($record))) $values .= ",";
$i++;
}
fwrite($h, "INSERT INTO `".$table."` VALUES (".$values.");\n");
}
}
fclose($h);
return true;
function hasCallback($name) { /* {{{ */
if($name && !empty($this->callbacks[$name]))
return true;
return false;
} /* }}} */
}