本文整理汇总了PHP中data_update_instance函数的典型用法代码示例。如果您正苦于以下问题:PHP data_update_instance函数的具体用法?PHP data_update_instance怎么用?PHP data_update_instance使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了data_update_instance函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
function import()
{
global $CFG;
list($settings, $newfields, $currentfields) = $this->get_settings();
$preservedfields = array();
$overwritesettings = optional_param('overwritesettings', 0, PARAM_BOOL);
/* Maps fields and makes new ones */
if (!empty($newfields)) {
/* We require an injective mapping, and need to know what to protect */
foreach ($newfields as $nid => $newfield) {
$cid = optional_param("field_{$nid}", -1, PARAM_INT);
if ($cid == -1) {
continue;
}
if (array_key_exists($cid, $preservedfields)) {
error("Not an injective map");
} else {
$preservedfields[$cid] = true;
}
}
foreach ($newfields as $nid => $newfield) {
$cid = optional_param("field_{$nid}", -1, PARAM_INT);
/* A mapping. Just need to change field params. Data kept. */
if ($cid != -1 and isset($currentfields[$cid])) {
$fieldobject = data_get_field_from_id($currentfields[$cid]->id, $this->data);
foreach ($newfield as $param => $value) {
if ($param != "id") {
$fieldobject->field->{$param} = $value;
}
}
unset($fieldobject->field->similarfield);
$fieldobject->update_field();
unset($fieldobject);
} else {
include_once "field/{$newfield->type}/field.class.php";
if (!isset($newfield->description)) {
$newfield->description = '';
}
$classname = 'data_field_' . $newfield->type;
$fieldclass = new $classname($newfield, $this->data);
$fieldclass->insert_field();
unset($fieldclass);
}
}
}
/* Get rid of all old unused data */
if (!empty($preservedfields)) {
foreach ($currentfields as $cid => $currentfield) {
if (!array_key_exists($cid, $preservedfields)) {
/* Data not used anymore so wipe! */
print "Deleting field {$currentfield->name}<br />";
$id = $currentfield->id;
//Why delete existing data records and related comments/ratings??
/*
if ($content = get_records('data_content', 'fieldid', $id)) {
foreach ($content as $item) {
delete_records('data_ratings', 'recordid', $item->recordid);
delete_records('data_comments', 'recordid', $item->recordid);
delete_records('data_records', 'id', $item->recordid);
}
}*/
delete_records('data_content', 'fieldid', $id);
delete_records('data_fields', 'id', $id);
}
}
}
// handle special settings here
if (!empty($settings->defaultsort)) {
if (is_numeric($settings->defaultsort)) {
// old broken value
$settings->defaultsort = 0;
} else {
$settings->defaultsort = (int) get_field('data_fields', 'id', 'dataid', $this->data->id, 'name', addslashes($settings->defaultsort));
}
} else {
$settings->defaultsort = 0;
}
// do we want to overwrite all current database settings?
if ($overwritesettings) {
// all supported settings
$overwrite = array_keys((array) $settings);
} else {
// only templates and sorting
$overwrite = array('singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter', 'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate', 'jstemplate', 'asearchtemplate', 'defaultsortdir', 'defaultsort');
}
// now overwrite current data settings
foreach ($this->data as $prop => $unused) {
if (in_array($prop, $overwrite)) {
$this->data->{$prop} = $settings->{$prop};
}
}
data_update_instance(addslashes_object($this->data));
if (strstr($this->folder, '/temp/')) {
// Removes the temporary files
clean_preset($this->folder);
}
return true;
}
示例2: import
//.........这里部分代码省略.........
global $DB, $CFG;
$params = $this->get_preset_settings();
$settings = $params->settings;
$newfields = $params->importfields;
$currentfields = $params->currentfields;
$preservedfields = array();
/* Maps fields and makes new ones */
if (!empty($newfields)) {
/* We require an injective mapping, and need to know what to protect */
foreach ($newfields as $nid => $newfield) {
$cid = optional_param("field_$nid", -1, PARAM_INT);
if ($cid == -1) {
continue;
}
if (array_key_exists($cid, $preservedfields)){
print_error('notinjectivemap', 'data');
}
else $preservedfields[$cid] = true;
}
foreach ($newfields as $nid => $newfield) {
$cid = optional_param("field_$nid", -1, PARAM_INT);
/* A mapping. Just need to change field params. Data kept. */
if ($cid != -1 and isset($currentfields[$cid])) {
$fieldobject = data_get_field_from_id($currentfields[$cid]->id, $this->module);
foreach ($newfield as $param => $value) {
if ($param != "id") {
$fieldobject->field->$param = $value;
}
}
unset($fieldobject->field->similarfield);
$fieldobject->update_field();
unset($fieldobject);
} else {
/* Make a new field */
include_once("field/$newfield->type/field.class.php");
if (!isset($newfield->description)) {
$newfield->description = '';
}
$classname = 'data_field_'.$newfield->type;
$fieldclass = new $classname($newfield, $this->module);
$fieldclass->insert_field();
unset($fieldclass);
}
}
}
/* Get rid of all old unused data */
if (!empty($preservedfields)) {
foreach ($currentfields as $cid => $currentfield) {
if (!array_key_exists($cid, $preservedfields)) {
/* Data not used anymore so wipe! */
print "Deleting field $currentfield->name<br />";
$id = $currentfield->id;
//Why delete existing data records and related comments/ratings??
$DB->delete_records('data_content', array('fieldid'=>$id));
$DB->delete_records('data_fields', array('id'=>$id));
}
}
}
// handle special settings here
if (!empty($settings->defaultsort)) {
if (is_numeric($settings->defaultsort)) {
// old broken value
$settings->defaultsort = 0;
} else {
$settings->defaultsort = (int)$DB->get_field('data_fields', 'id', array('dataid'=>$this->module->id, 'name'=>$settings->defaultsort));
}
} else {
$settings->defaultsort = 0;
}
// do we want to overwrite all current database settings?
if ($overwritesettings) {
// all supported settings
$overwrite = array_keys((array)$settings);
} else {
// only templates and sorting
$overwrite = array('singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter',
'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate', 'jstemplate',
'asearchtemplate', 'defaultsortdir', 'defaultsort');
}
// now overwrite current data settings
foreach ($this->module as $prop=>$unused) {
if (in_array($prop, $overwrite)) {
$this->module->$prop = $settings->$prop;
}
}
data_update_instance($this->module);
return $this->cleanup();
}
示例3: import
/**
* import()
* TODO document
*/
function import()
{
global $CFG;
list($settings, $newfields, $currentfields) = $this->load_from_file();
$preservedfields = array();
/* Maps fields and makes new ones */
if (!empty($newfields)) {
/* We require an injective mapping, and need to know what to protect */
foreach ($newfields as $nid => $newfield) {
$cid = optional_param("field_{$nid}", -1, PARAM_INT);
if ($cid == -1) {
continue;
}
if (array_key_exists($cid, $preservedfields)) {
print_error('notinjectivemap', 'data');
} else {
$preservedfields[$cid] = true;
}
}
foreach ($newfields as $nid => $newfield) {
$cid = optional_param("field_{$nid}", -1, PARAM_INT);
/* A mapping. Just need to change field params. Data kept. */
if ($cid != -1 and isset($currentfelds[$cid])) {
$fieldobject = data_get_field_from_id($currentfields[$cid]->id, $this->data);
foreach ($newfield as $param => $value) {
if ($param != "id") {
$fieldobject->field->{$param} = $value;
}
}
unset($fieldobject->field->similarfield);
$fieldobject->update_field();
unset($fieldobject);
} else {
include_once "field/{$newfield->type}/field.class.php";
if (!isset($newfield->description)) {
$newfield->description = '';
}
$classname = 'data_field_' . $newfield->type;
$fieldclass = new $classname($newfield, $this->data);
$fieldclass->insert_field();
unset($fieldclass);
}
}
}
/* Get rid of all old unused data */
if (!empty($preservedfields)) {
foreach ($currentfields as $cid => $currentfield) {
if (!array_key_exists($cid, $preservedfields)) {
/* Data not used anymore so wipe! */
print "Deleting field {$currentfield->name}<br />";
$id = $currentfield->id;
// Why delete existing data records and related comments/ratings ??
/*
if ($content = get_records('data_content', 'fieldid', $id)) {
foreach ($content as $item) {
delete_records('data_ratings', 'recordid', $item->recordid);
delete_records('data_comments', 'recordid', $item->recordid);
delete_records('data_records', 'id', $item->recordid);
}
}
*/
delete_records('data_content', 'fieldid', $id);
delete_records('data_fields', 'id', $id);
}
}
}
data_update_instance(addslashes_object($settings));
if (strstr($this->directory, '/temp/')) {
clean_preset($this->directory);
}
/* Removes the temporary files */
return true;
}