public function controller_create($args) { $vars["success"] = null; $vars["varname"] = "newdemo"; $tablename = "demos"; $objkey = "demoname"; if (!empty($args["category"]) || !empty($args["newcategory"])) { $vars["varname"] = "newcategory"; $tablename = "demo_categories"; $objkey = "category"; } if (!empty($args[$vars["varname"]])) { $newobj = $args[$vars["varname"]]; $newobjid = $newobj[$objkey]; if (!empty($newobj[$objkey]) && !empty($newobj["title"])) { $vars["success"] = DataManager::insert("db.demos.{$newobjid}", $tablename, $newobj); if (!$vars["success"]) { // insert failed, try an update $vars["success"] = DataManager::update("db.demos.{$newobjid}", $tablename, $newobj, array($objkey => $newobjid)); } } $vars["demo"] = $newobj; } else { if (!empty($args["category"])) { $vars["varname"] = "newcategory"; $demos = DataManager::fetch("db.demos.{$args['category']}", "demo_categories", array($objkey => $args["category"])); $vars["demo"] = $demos[0]; } else { if (!empty($args["demoname"])) { $demos = DataManager::fetch("db.demos.{$args['demoname']}", "demos", array("demoname" => $args["demoname"])); $vars["demo"] = $demos[0]; } } } return $this->GetComponentResponse("./create.tpl", $vars); }
/** * Update a specific config entry (diffs only) * * @param string $name name of config to update * @param array $newcfg new configuration object to compare with * @return array */ function Update($name, $newcfg, $role = "", $deletecfg = null, $skipLocalConfig = false, $addedcfg = null) { $ret = false; $updaterevision = false; $this->Load($name, $role, $skipLocalConfig); $oldcfg = $this->configs[$name]; $cobrandid = $oldcfg["cobrandid"]; $oldrevision = $oldcfg["revision"]; //remove revision key / value pair. It should be auto incremented unset($oldcfg["revision"]); //unset($newcfg["revision"]); /* $diff = array_diff_assoc_recursive($newcfg, $oldcfg); $configupdates = $this->FlattenConfig($diff); */ $configdeletes = $this->FlattenConfig($deletecfg); if (count($newcfg) > 0) { foreach ($newcfg as $k => $v) { Logger::Debug('ConfigManager Update: [' . $name . ' ' . $cobrandid . ' ' . $role . '] ' . $k . ' = ' . $v["value"] . ' : ' . $v["type"]); $response = DataManager::Query("db.config.cobrand_config.{$name}-{$k}:nocache", "UPDATE config.cobrand_config SET value=:value, type=:type, modified_time=:timestamp WHERE name=:name AND cobrandid=:cobrandid AND role=:role", array(":value" => $v["value"], ":type" => $v["type"], ":name" => $k, ":cobrandid" => $cobrandid, ":role" => $role, ":timestamp" => unixtime_milli())); if (!empty($response) && $response->numrows > 0) { $ret = true; } } $updaterevision = true; } // process the inserts en-masse if (count($addedcfg) > 0) { $keyvalues = array(); foreach ($addedcfg as $k => $v) { $keyvalues[] = array("ccid" => md5int64($role . '-' . $cobrandid . '-' . $k), "cobrandid" => $cobrandid, "name" => $k, "value" => $v["value"], "type" => $v["type"], 'role' => $role); } if (!empty($keyvalues)) { $query = DataManager::insert("db.config.cobrand_config.{$name}-{$k}:nocache", "config.cobrand_config", $keyvalues); $ret |= true; } $updaterevision = true; } // process the deletes if (count($configdeletes) > 0) { /* foreach ($configdeletes as $k=>$v) { if ($configdeletes[$k]) { $query = DataManager::query("db.config.cobrand_config.delete.{$name}-{$k}:nocache", "DELETE FROM config.cobrand_config WHERE name=:name AND cobrandid=:cobrandid and role=:role", array(":name" => $k, ":cobrandid" => $cobrandid, ":role" => $role)); $ret |= true; } } */ /* FIXME - code above deletes one-by-one, this code deletes en-masse. Should we switch to this instead? */ /* yes i believe so. -lazarus */ $deletes = array(); foreach ($configdeletes as $k => $v) { if ($v == 1) { $deletes[] = "'{$k}'"; } } if (!empty($deletes)) { $deletestr = implode(",", $deletes); // FIXME - doesn't PDO have a better way to handle "IN ('blah','asdf') type statements? $query = DataManager::query("db.config.cobrand_config.delete.{$name}-{$k}:nocache", "DELETE FROM config.cobrand_config WHERE cobrandid=:cobrandid AND role=:role AND name IN ({$deletestr})", array(":cobrandid" => $cobrandid, ":role" => $role)); $ret |= true; } $updaterevision = true; } if ($updaterevision) { $this->UpdateRevision($cobrandid, $role); DataManager::CacheClear("db.config.cobrand_config.{$name}.{$role}"); DataManager::CacheClear("db.config.version.{$name}.{$role}"); } if ($ret) { DataManager::CacheClear("db.config.cobrand_config.{$name}.{$role}"); } return $ret; }