本文整理汇总了PHP中XMLDBIndex::setUnique方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLDBIndex::setUnique方法的具体用法?PHP XMLDBIndex::setUnique怎么用?PHP XMLDBIndex::setUnique使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLDBIndex
的用法示例。
在下文中一共展示了XMLDBIndex::setUnique方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmldb_main_upgrade
//.........这里部分代码省略.........
$table->comment = 'Group functions or methods under a service';
// fields
$f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('rpcid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
// PK and indexes
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addIndexInfo('unique', XMLDB_INDEX_UNIQUE, array('rpcid', 'serviceid'));
// Create the table
$result = $result && create_table($table);
//
// Prime MNET configuration entries -- will be needed later by auth/mnet
//
include_once $CFG->dirroot . '/mnet/lib.php';
$env = new mnet_environment();
$env->init();
unset($env);
// add mnethostid to user-
$table = new XMLDBTable('user');
$field = new XMLDBField('mnethostid');
$field->setType(XMLDB_TYPE_INTEGER);
$field->setLength(10);
$field->setNotNull(true);
$field->setSequence(null);
$field->setEnum(null);
$field->setDefault('0');
$field->setPrevious("deleted");
$field->setNext("username");
$result = $result && add_field($table, $field);
// The default mnethostid is zero... we need to update this for all
// users of the local IdP service.
set_field('user', 'mnethostid', $CFG->mnet_localhost_id, 'mnethostid', '0');
$index = new XMLDBIndex('username');
$index->setUnique(true);
$index->setFields(array('username'));
drop_index($table, $index);
$index->setFields(array('mnethostid', 'username'));
if (!add_index($table, $index)) {
notify(get_string('duplicate_usernames', 'mnet', 'http://docs.moodle.org/en/DuplicateUsernames'));
}
unset($table, $field, $index);
/**
** auth/mnet tables
**/
$table = new XMLDBTable('mnet_session');
$table->comment = 'Store session data from users migrating to other sites';
// fields
$f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('token', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('mnethostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('useragent', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('confirm_timeout', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('session_id', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('expires', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
// PK and indexes
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addIndexInfo('token', XMLDB_INDEX_UNIQUE, array('token'));
// Create the table
$result = $result && create_table($table);
$table = new XMLDBTable('mnet_sso_access_control');
$table->comment = 'Users by host permitted (or not) to login from a remote provider';
$f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('mnet_host_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
示例2: invoke
//.........这里部分代码省略.........
$uniquearr = array_unique($fieldsarr);
if (count($fieldsarr) != count($uniquearr)) {
$errors[] = $this->str['duplicatefieldsused'];
}
/// Check that all the fields in belong to the table
foreach ($fieldsarr as $field) {
if (!$table->getField($field)) {
$errors[] = $this->str['fieldsnotintable'];
break;
}
}
/// Check that there isn't any key using exactly the same fields
$tablekeys = $table->getKeys();
if ($tablekeys) {
foreach ($tablekeys as $tablekey) {
$keyfieldsarr = $tablekey->getFields();
/// Compare both arrays, looking for diferences
$diferences = array_merge(array_diff($fieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $fieldsarr));
if (empty($diferences)) {
$errors[] = $this->str['fieldsusedinkey'];
break;
}
}
}
/// Check that there isn't any index using exactlt the same fields
$tableindexes = $table->getIndexes();
if ($tableindexes) {
foreach ($tableindexes as $tableindex) {
/// Skip checking against itself
if ($indexparam == $tableindex->getName()) {
continue;
}
$indexfieldsarr = $tableindex->getFields();
/// Compare both arrays, looking for diferences
$diferences = array_merge(array_diff($fieldsarr, $indexfieldsarr), array_diff($indexfieldsarr, $fieldsarr));
if (empty($diferences)) {
$errors[] = $this->str['fieldsusedinindex'];
break;
}
}
}
}
if (!empty($errors)) {
$tempindex = new XMLDBIndex($name);
$tempindex->setUnique($unique);
$tempindex->setFields($fieldsarr);
/// Prepare the output
$site = get_site();
$navlinks = array();
$navlinks[] = array('name' => $this->str['administration'], 'link' => '../index.php', 'type' => 'misc');
$navlinks[] = array('name' => 'XMLDB', 'link' => 'index.php', 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("{$site->shortname}: XMLDB", "{$site->fullname}", $navigation);
notice('<p>' . implode(', ', $errors) . '</p>
<p>' . $tempindex->readableInfo(), 'index.php?action=edit_index&index=' . $index->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)));
die;
/// re-die :-P
}
/// Continue if we aren't under errors
if (empty($errors)) {
/// If there is one name change, do it, changing the prev and next
/// atributes of the adjacent fields
if ($indexparam != $name) {
$index->setName($name);
if ($index->getPrevious()) {
$prev =& $table->getIndex($index->getPrevious());
$prev->setNext($name);
$prev->setChanged(true);
}
if ($index->getNext()) {
$next =& $table->getIndex($index->getNext());
$next->setPrevious($name);
$next->setChanged(true);
}
}
/// Set comment
$index->setComment($comment);
/// Set the rest of fields
$index->setUnique($unique);
$index->setFields($fieldsarr);
/// If the hash has changed from the old one, change the version
/// and mark the structure as changed
$index->calculateHash(true);
if ($oldhash != $index->getHash()) {
$index->setChanged(true);
$table->setChanged(true);
/// Recalculate the structure hash
$structure->calculateHash(true);
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
/// Mark as changed
$structure->setChanged(true);
}
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
}
/// Return ok if arrived here
return $result;
}
示例3: xmldb_main_upgrade
//.........这里部分代码省略.........
$table->comment = 'Group functions or methods under a service';
// fields
$f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$f = $table->addFieldInfo('serviceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('rpcid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
// PK and indexes
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addIndexInfo('unique', XMLDB_INDEX_UNIQUE, array('rpcid', 'serviceid'));
// Create the table
$result = $result && create_table($table);
//
// Prime MNET configuration entries -- will be needed later by auth/mnet
//
include_once $CFG->dirroot . '/mnet/lib.php';
$env = new mnet_environment();
$env->init();
unset($env);
// add mnethostid to user-
$table = new XMLDBTable('user');
$field = new XMLDBField('mnethostid');
$field->setType(XMLDB_TYPE_INTEGER);
$field->setLength(10);
$field->setNotNull(true);
$field->setSequence(null);
$field->setEnum(null);
$field->setDefault('0');
$field->setPrevious("deleted");
$field->setNext("username");
$result = $result && add_field($table, $field);
// The default mnethostid is zero... we need to update this for all
// users of the local IdP service.
set_field('user', 'mnethostid', $CFG->mnet_localhost_id, 'mnethostid', '0');
$index = new XMLDBIndex('username');
$index->setUnique(true);
$index->setFields(array('username'));
drop_index($table, $index);
$index->setFields(array('mnethostid', 'username'));
if (!add_index($table, $index)) {
notify(get_string('duplicate_usernames', 'mnet', 'http://docs.moodle.org/en/DuplicateUsernames'));
}
unset($table, $field, $index);
/**
** auth/mnet tables
**/
$table = new XMLDBTable('mnet_session');
$table->comment = 'Store session data from users migrating to other sites';
// fields
$f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$f = $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('token', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('mnethostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('useragent', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('confirm_timeout', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
$f = $table->addFieldInfo('session_id', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('expires', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);
// PK and indexes
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addIndexInfo('token', XMLDB_INDEX_UNIQUE, array('token'));
// Create the table
$result = $result && create_table($table);
$table = new XMLDBTable('mnet_sso_access_control');
$table->comment = 'Users by host permitted (or not) to login from a remote provider';
$f = $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', false, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$f = $table->addFieldInfo('username', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, NULL, null, null, null);
$f = $table->addFieldInfo('mnet_host_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, NULL, null, null, 0);