<?php error_reporting(E_ALL); require_once 'conf_global.php'; require_once PATH_EYOUM_LIB . 'em_db.class.php'; require_once PATH_EYOUM_LIB . 'em_member.class.php'; require_once PATH_EYOUM_LIB . 'db/em_db_expr.class.php'; require_once PATH_EYOUM_LIB . 'em_transaction.class.php'; $domain_name = 'test.com'; $acct_name = 'libo'; $trans = new em_transaction(); $domain_key = em_member::property_factory('domain_key', array('domain_name' => $domain_name)); $user_key = em_member::property_factory('user_key', array('acct_name' => $acct_name)); $user_key->set_domain_key($domain_key); $user = em_member::operator_factory('user', $user_key); $attr = array('password' => 'aaaaa123'); $property['basic'] = em_member::property_factory('user_basic', $attr); $trans->begin(); try { $user->add_user($property); $trans->commit(); } catch (em_exception $e) { $trans->rollback(); echo $e; }
function mod_app($app_name, $app_version, $json) { $data = json_decode($json, true); if (!$data) { error_exit("invalid json:\n{$json}"); } $os_app = new em_os_app(); if (!isset($app_version)) { $condition = em_condition::factory('os:app', 'app:find_app'); $condition->set_prefix(em_os::PREFIX_APP); $condition->set_columns(array('version')); $condition->set_eq('app', $app_name); $tmp = $os_app->find_app($condition); if (!$tmp) { error_exit('Not Found.'); } if (1 != count($tmp)) { error_exit('Found ' . count($tmp) . ' record for `' . $app_name . '`'); } $app_version = $tmp[0]['version']; } $trans = new em_transaction(); $trans->begin(); $app_property = em_os::property_factory('app', $data); check_property($app_property); $os_app->get_operator('app')->mod_app_by_name($app_name, $app_version, $app_property); $app_info = $os_app->get_operator('app')->fetch_app_by_name($app_name, $app_version); $os_app_id = $app_info['os_app_id']; $app_property->set_os_app_id($os_app_id); foreach (array('win', 'link', 'action') as $type) { if (!isset($data[$type])) { continue; } if (!is_array($data[$type])) { error_exit("invalid `{$type}` data:\n" . $data[$type]); } foreach ($data[$type] as $name => $attributes) { if (!is_numeric($name) && isset($attributes[$type])) { $name = $attributes[$type]; } unset($attributes[$type]); $property = em_os::property_factory("app_{$type}", $attributes); $property->set_app($app_property); check_property($property); if (isset($app_info[$type][$name])) { $os_app->get_operator("app_{$type}")->{"mod_app_{$type}_by_name"}($os_app_id, $name, $property); unset($app_info[$type][$name]); } else { $property->{"set_{$type}"}($name); $os_app->get_operator("app_{$type}")->{"add_app_{$type}"}($property); } } } foreach (array('win', 'link', 'action') as $type) { if (empty($app_info[$type])) { continue; } $os_app->get_operator("app_{$type}")->{"del_app_{$type}_by_id"}($os_app_id, $app_info[$type]); } $trans->commit(); echo "+OK\n"; exit(0); }