本文整理汇总了PHP中commit_sql函数的典型用法代码示例。如果您正苦于以下问题:PHP commit_sql函数的具体用法?PHP commit_sql怎么用?PHP commit_sql使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了commit_sql函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: finish_transaction
/**
* Ends a (possibly nested) transaction.
*/
static function finish_transaction()
{
self::$transactions--;
if (self::$transactions == 0) {
commit_sql();
}
}
示例2: cleanup_contexts
/**
* Remove stale context records
*
* @return bool
*/
function cleanup_contexts()
{
global $CFG;
$sql = " SELECT c.contextlevel,\n c.instanceid AS instanceid\n FROM {$CFG->prefix}context c\n LEFT OUTER JOIN {$CFG->prefix}course_categories t\n ON c.instanceid = t.id\n WHERE t.id IS NULL AND c.contextlevel = " . CONTEXT_COURSECAT . "\n UNION\n SELECT c.contextlevel,\n c.instanceid\n FROM {$CFG->prefix}context c\n LEFT OUTER JOIN {$CFG->prefix}course t\n ON c.instanceid = t.id\n WHERE t.id IS NULL AND c.contextlevel = " . CONTEXT_COURSE . "\n UNION\n SELECT c.contextlevel,\n c.instanceid\n FROM {$CFG->prefix}context c\n LEFT OUTER JOIN {$CFG->prefix}course_modules t\n ON c.instanceid = t.id\n WHERE t.id IS NULL AND c.contextlevel = " . CONTEXT_MODULE . "\n UNION\n SELECT c.contextlevel,\n c.instanceid\n FROM {$CFG->prefix}context c\n LEFT OUTER JOIN {$CFG->prefix}user t\n ON c.instanceid = t.id\n WHERE t.id IS NULL AND c.contextlevel = " . CONTEXT_USER . "\n UNION\n SELECT c.contextlevel,\n c.instanceid\n FROM {$CFG->prefix}context c\n LEFT OUTER JOIN {$CFG->prefix}block_instance t\n ON c.instanceid = t.id\n WHERE t.id IS NULL AND c.contextlevel = " . CONTEXT_BLOCK . "\n ";
if ($rs = get_recordset_sql($sql)) {
begin_sql();
$tx = true;
while ($tx && ($ctx = rs_fetch_next_record($rs))) {
$tx = $tx && delete_context($ctx->contextlevel, $ctx->instanceid);
}
rs_close($rs);
if ($tx) {
commit_sql();
return true;
}
rollback_sql();
return false;
rs_close($rs);
}
return true;
}
示例3: dialogue_cron
//.........这里部分代码省略.........
$rs = get_recordset_select('dialogue_conversations', 'grouping != 0 AND grouping IS NOT NULL', 'dialogueid, grouping');
$dialogueid = 0;
$grouping = 0;
$groupid = null;
$inconversation = array();
$newusers = array();
while ($conversation = rs_fetch_next_record($rs)) {
if ($dialogueid != $conversation->dialogueid || $groupid != $conversation->groupid || $grouping != $conversation->grouping) {
if ($dialogueid == 0 || $groupid === null) {
$dialogueid = $conversation->dialogueid;
$groupid = $conversation->groupid;
}
$cm = get_coursemodule_from_instance('dialogue', $dialogueid);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$users = (array) get_users_by_capability($context, 'mod/dialogue:participate', 'u.id, u.firstname, u.lastname', null, null, null, empty($groupid) ? null : $groupid, null, null, null, false);
$managers = (array) get_users_by_capability($context, 'mod/dialogue:manage', 'u.id, u.firstname, u.lastname', null, null, null, null, null, null, null, false);
$dialogueid = $conversation->dialogueid;
$groupid = $conversation->groupid;
}
if ($grouping != $conversation->grouping) {
if ($grouping) {
if ($userdiff = array_diff_key($users, $inconversation, $managers)) {
foreach ($userdiff as $userid => $value) {
$newusers[$userid . ',' . $grouping] = array('userid' => $userid, 'courseid' => $cm->course, 'grouping' => $grouping);
}
}
}
$inconversation = array();
$grouping = $conversation->grouping;
}
$inconversation[$conversation->recipientid] = true;
}
if (!empty($dialogueid)) {
// Finish of any remaing users
$cm = get_coursemodule_from_instance('dialogue', $dialogueid);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$users = (array) get_users_by_capability($context, 'mod/dialogue:participate', 'u.id, u.firstname, u.lastname', null, null, null, empty($groupid) ? null : $groupid, null, null, null, false);
$managers = (array) get_users_by_capability($context, 'mod/dialogue:manage', 'u.id, u.firstname, u.lastname', null, null, null, null, null, null, null, false);
if ($userdiff = array_diff_key($users, $inconversation, $managers)) {
foreach ($userdiff as $userid => $value) {
$newusers[$userid . ',' . $grouping] = array('userid' => $userid, 'courseid' => $cm->course, 'grouping' => $grouping);
}
}
}
rs_close($rs);
if (!empty($newusers)) {
foreach ($newusers as $key => $newuser) {
begin_sql();
course_setup($newuser['courseid']);
if ($conversations = get_records('dialogue_conversations', 'grouping', $newuser['grouping'], 'id', '*', 0, 1)) {
$conversation = array_pop($conversations);
// we only need one to get the common field values
if ($entry = get_records('dialogue_entries', 'conversationid', $conversation->id, 'id', '*', 0, 1)) {
unset($conversation->id);
$conversation->recipientid = $newuser['userid'];
$conversation->lastrecipientid = $newuser['userid'];
$conversation->timemodified = time();
$conversation->seenon = false;
$conversation->closed = 0;
$conversation = addslashes_object($conversation);
if (!($conversationid = insert_record('dialogue_conversations', $conversation))) {
rollback_sql();
continue;
}
$entry = array_pop($entry);
$srcentry = clone $entry;
unset($entry->id);
$entry->conversationid = $conversationid;
$entry->timecreated = $conversation->timemodified;
$entry->recipientid = $conversation->recipientid;
$entry->mailed = false;
$entry = addslashes_object($entry);
if (!($entry->id = insert_record('dialogue_entries', $entry))) {
rollback_sql();
continue;
}
$read = new stdClass();
$lastread = time();
$read->conversationid = $conversationid;
$read->entryid = $entry->id;
$read->userid = $conversation->userid;
$read->firstread = $lastread;
$read->lastread = $lastread;
insert_record('dialogue_read', $read);
if ($entry->attachment) {
$srcdir = dialogue_file_area($srcentry);
$dstdir = dialogue_file_area($entry);
copy($srcdir . '/' . $entry->attachment, $dstdir . '/' . $entry->attachment);
}
} else {
mtrace('Failed to find entry for conversation: ' . $conversation->id);
}
} else {
mtrace('Failed to find conversation: ' . $conversation->id);
}
commit_sql();
}
}
return true;
}
示例4: fix_coursecategory_orphans
/**
* Ensure all courses have a valid course category
* useful if a category has been removed manually
**/
function fix_coursecategory_orphans()
{
global $CFG;
// Note: the handling of sortorder here is arguably
// open to race conditions. Hard to fix here, unlikely
// to hit anyone in production.
$sql = "SELECT c.id, c.category, c.shortname\n FROM {$CFG->prefix}course c\n LEFT OUTER JOIN {$CFG->prefix}course_categories cc ON c.category=cc.id\n WHERE cc.id IS NULL AND c.id != " . SITEID;
$rs = get_recordset_sql($sql);
if (!rs_EOF($rs)) {
// we have some orphans
// the "default" category is the lowest numbered...
$default = get_field_sql("SELECT MIN(id)\n FROM {$CFG->prefix}course_categories");
$sortorder = get_field_sql("SELECT MAX(sortorder)\n FROM {$CFG->prefix}course\n WHERE category={$default}");
begin_sql();
$tx = true;
while ($tx && ($course = rs_fetch_next_record($rs))) {
$tx = $tx && set_field('course', 'category', $default, 'id', $course->id);
$tx = $tx && set_field('course', 'sortorder', ++$sortorder, 'id', $course->id);
}
if ($tx) {
commit_sql();
} else {
rollback_sql();
}
}
rs_close($rs);
}
示例5: restore
/**
* Restores the data in the question
*
* This is used in question/restorelib.php
*/
function restore($old_question_id, $new_question_id, $info, $restore)
{
$status = begin_sql();
$minfo = $info['#']['MATRIX'];
$newmatrix = (object) array('questionid' => $new_question_id, 'grademethod' => backup_todb($minfo[0]['#']['GRADEMETHOD']['0']['#']), 'multiple' => backup_todb($minfo[0]['#']['MULTIPLE']['0']['#']), 'renderer' => backup_todb($minfo[0]['#']['RENDERER']['0']['#']));
$newmatrix->id = insert_record('question_matrix', $newmatrix);
$rows = $minfo[0]['#']['ROWS'][0]['#']['ROW'];
// why does this get eaten?!
$rowmapping = array();
foreach ($rows as $row) {
$row = $row['#'];
// more nonsense
$newrow = (object) array('matrixid' => $newmatrix->id, 'shorttext' => backup_todb($row['SHORTTEXT']['0']['#']), 'description' => backup_todb($row['DESCRIPTION']['0']['#']), 'feedback' => backup_todb($row['FEEDBACK']['0']['#']));
$status = $status && ($rowmapping[backup_todb($row['ID']['0']['#'])] = insert_record('question_matrix_rows', $newrow));
}
$cols = $minfo[0]['#']['COLS'][0]['#']['COL'];
// why does this get eaten?!
$colmapping = array();
foreach ($cols as $col) {
$col = $col['#'];
// more nonsense
$newcol = (object) array('matrixid' => $newmatrix->id, 'shorttext' => backup_todb($col['SHORTTEXT']['0']['#']), 'description' => backup_todb($col['DESCRIPTION']['0']['#']));
$status = $status && ($colmapping[backup_todb($col['ID']['0']['#'])] = insert_record('question_matrix_cols', $newcol));
}
$weights = $minfo[0]['#']['WEIGHTS'][0]['#']['WEIGHT'];
foreach ($weights as $weight) {
$weight = $weight['#'];
$newweight = (object) array('rowid' => $rowmapping[backup_todb($weight['ROWID'][0]['#'])], 'colid' => $colmapping[backup_todb($weight['COLID'][0]['#'])], 'weight' => backup_todb($weight['WEIGHT'][0]['#']));
$status = $status && insert_record('question_matrix_weights', $newweight);
}
return $status && commit_sql();
}
示例6: update
/**
* Adds a new document or updates an existing one. The necessary set_
* methods must already have been called.
* @param string $title Document title (plain text)
* @param string $content Document content (XHTML)
* @param int $timemodified Optional modified time (defaults to now)
* @param int $timeexpires Optional expiry time (defaults to none); if
* expiry time is included then module must provide a
* modulename_ousearch_update($document=null) function
* @param mixed $extrastrings An array of additional strings which are
* searchable, but not included as part of the document content (for
* display to users etc). This can be used for keywords and the like
* @return True for success, false for failure
*/
function update($title, $content, $timemodified = null, $timeexpires = null, $extrastrings = null)
{
global $OUSEARCH_NO_TRANSACTIONS;
if (empty($OUSEARCH_NO_TRANSACTIONS)) {
begin_sql();
}
// Find document ID, creating document if needed
if (!$this->find()) {
// Arse around with slashes so we can insert it safely
// but the data is corrected again later.
if (!empty($this->stringref)) {
$beforestringref = $this->stringref;
$this->stringref = addslashes($this->stringref);
}
$beforeplugin = $this->plugin;
$this->plugin = addslashes($this->plugin);
$ok = insert_record('block_ousearch_documents', $this);
if (!empty($beforestringref)) {
$this->stringref = $beforestringref;
}
$this->plugin = $beforeplugin;
if (!$ok) {
debugging('Failed to add ousearch document');
if (empty($OUSEARCH_NO_TRANSACTIONS)) {
rollback_sql();
}
return false;
}
$this->id = $ok;
}
// Update document record if needed
if ($timemodified || $timeexpires) {
$update = new StdClass();
$update->id = $this->id;
if ($timemodified) {
$update->timemodified = $timemodified;
}
if ($timeexpires) {
$update->timeexpires = $timeexpires;
}
if (!update_record('block_ousearch_documents', $update)) {
debugging('Failed to update document record');
if (empty($OUSEARCH_NO_TRANSACTIONS)) {
rollback_sql();
}
return false;
}
}
// Delete existing words
if (!delete_records('block_ousearch_occurrences', 'documentid', $this->id)) {
debugging('Failed to delete occurrences for ousearch document ' . $this->id);
if (empty($OUSEARCH_NO_TRANSACTIONS)) {
rollback_sql();
}
return false;
}
// Extra strings are just counted as more content in the database
if ($extrastrings) {
foreach ($extrastrings as $string) {
$content .= ' ' . $string;
}
}
// Add new words
$result = $this->internal_add_words($title, $content);
if (empty($OUSEARCH_NO_TRANSACTIONS)) {
commit_sql();
}
return $result;
}
示例7: Ejercicios_texto_texto_resp
$resp_txt = new Ejercicios_texto_texto_resp(NULL, $id_pregunta, $resp_textarea, 0);
$resp_txt->insertar();
}
}
echo "insertado";
}
} else {
if ($tipo_origen == 4) {
// ES UNA IMAGEN
if ($tipo_respuesta == 1) {
//La respuesta es un texto
//$preg = required_param('pregunta' . $j, PARAM_TEXT);
$preg = "foto_" . $id_ejercicio . "_" . $j . ".jpg";
$ejercicio_texto_preg = new Ejercicios_texto_texto_preg(NULL, $id_ejercicio, $preg);
$id_pregunta = $ejercicio_texto_preg->insertar();
$ejercicio_texto_img = new Ejercicios_imagenes_asociadas($NULL, $id_ejercicio, $id_pregunta, $preg);
$ejercicio_texto_img->insertar();
$num_resp = required_param('num_res_preg' . $j, PARAM_INT);
for ($k = 1; $k <= $num_resp; $k++) {
$resp_textarea = required_param("respuesta" . $k . "_" . $j, PARAM_TEXT);
$resp_txt = new Ejercicios_texto_texto_resp(NULL, $id_pregunta, $resp_textarea, 0);
$resp_txt->insertar();
}
}
}
}
}
}
}
commit_sql();
redirect('./view.php?id=' . $id_curso . '&opcion=9');
示例8: delete_user
/**
* Marks user deleted in internal user database and notifies the auth plugin.
* Also unenrols user from all roles and does other cleanup.
* @param object $user Userobject before delete (without system magic quotes)
* @return boolean success
*/
function delete_user($user)
{
global $CFG;
require_once $CFG->libdir . '/grouplib.php';
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/message/lib.php';
begin_sql();
// delete all grades - backup is kept in grade_grades_history table
if ($grades = grade_grade::fetch_all(array('userid' => $user->id))) {
foreach ($grades as $grade) {
$grade->delete('userdelete');
}
}
//move unread messages from this user to read
message_move_userfrom_unread2read($user->id);
// remove from all groups
delete_records('groups_members', 'userid', $user->id);
// unenrol from all roles in all contexts
role_unassign(0, $user->id);
// this might be slow but it is really needed - modules might do some extra cleanup!
// now do a final accesslib cleanup - removes all role assingments in user context and context itself
delete_context(CONTEXT_USER, $user->id);
require_once $CFG->dirroot . '/tag/lib.php';
tag_set('user', $user->id, array());
// workaround for bulk deletes of users with the same email address
$delname = addslashes("{$user->email}." . time());
while (record_exists('user', 'username', $delname)) {
// no need to use mnethostid here
$delname++;
}
// mark internal user record as "deleted"
$updateuser = new object();
$updateuser->id = $user->id;
$updateuser->deleted = 1;
$updateuser->username = $delname;
// Remember it just in case
$updateuser->email = md5($user->username);
// Store hash of username, useful importing/restoring users
$updateuser->idnumber = '';
// Clear this field to free it up
$updateuser->timemodified = time();
if (update_record('user', $updateuser)) {
commit_sql();
// notify auth plugin - do not block the delete even when plugin fails
$authplugin = get_auth_plugin($user->auth);
$authplugin->user_delete($user);
events_trigger('user_deleted', $user);
return true;
} else {
rollback_sql();
return false;
}
}
示例9: sync_users
//.........这里部分代码省略.........
$fresult = array();
foreach ($contexts as $context) {
$context = trim($context);
if (empty($context)) {
continue;
}
begin_sql();
if ($this->config->search_sub) {
//use ldap_search to find first user from subtree
$ldap_result = ldap_search($ldapconnection, $context, $filter, array($this->config->user_attribute));
} else {
//search only in this context
$ldap_result = ldap_list($ldapconnection, $context, $filter, array($this->config->user_attribute));
}
if ($entry = ldap_first_entry($ldapconnection, $ldap_result)) {
do {
$value = ldap_get_values_len($ldapconnection, $entry, $this->config->user_attribute);
$value = $textlib->convert($value[0], $this->config->ldapencoding, 'utf-8');
// usernames are __always__ lowercase.
array_push($fresult, moodle_strtolower($value));
if (count($fresult) >= $bulk_insert_records) {
$this->ldap_bulk_insert($fresult, $temptable);
$fresult = array();
}
} while ($entry = ldap_next_entry($ldapconnection, $entry));
}
unset($ldap_result);
// free mem
// insert any remaining users and release mem
if (count($fresult)) {
$this->ldap_bulk_insert($fresult, $temptable);
$fresult = array();
}
commit_sql();
}
/// preserve our user database
/// if the temp table is empty, it probably means that something went wrong, exit
/// so as to avoid mass deletion of users; which is hard to undo
$count = get_record_sql('SELECT COUNT(username) AS count, 1 FROM ' . $temptable);
$count = $count->{'count'};
if ($count < 1) {
print "Did not get any users from LDAP -- error? -- exiting\n";
exit;
} else {
print "Got {$count} records from LDAP\n\n";
}
/// User removal
// find users in DB that aren't in ldap -- to be removed!
// this is still not as scalable (but how often do we mass delete?)
if (!empty($this->config->removeuser)) {
$sql = "SELECT u.id, u.username, u.email, u.auth \n FROM {$CFG->prefix}user u\n LEFT JOIN {$temptable} e ON u.username = e.username\n WHERE u.auth='ldap'\n AND u.deleted=0\n AND e.username IS NULL";
$remove_users = get_records_sql($sql);
if (!empty($remove_users)) {
print "User entries to remove: " . count($remove_users) . "\n";
foreach ($remove_users as $user) {
if ($this->config->removeuser == 2) {
if (delete_user($user)) {
echo "\t";
print_string('auth_dbdeleteuser', 'auth', array($user->username, $user->id));
echo "\n";
} else {
echo "\t";
print_string('auth_dbdeleteusererror', 'auth', $user->username);
echo "\n";
}
} else {
示例10: stats_upgrade_for_roles_wrapper
function stats_upgrade_for_roles_wrapper()
{
global $CFG;
if (!empty($CFG->statsrolesupgraded)) {
return true;
}
$result = begin_sql();
$result = $result && stats_upgrade_user_table_for_roles('daily');
$result = $result && stats_upgrade_user_table_for_roles('weekly');
$result = $result && stats_upgrade_user_table_for_roles('monthly');
$result = $result && stats_upgrade_table_for_roles('daily');
$result = $result && stats_upgrade_table_for_roles('weekly');
$result = $result && stats_upgrade_table_for_roles('monthly');
$result = $result && commit_sql();
if (!empty($result)) {
set_config('statsrolesupgraded', time());
}
// finally upgade totals, no big deal if it fails
stats_upgrade_totals();
return $result;
}
示例11: quiz_delete_userdata
/**
* Actual implementation of the rest coures functionality, delete all the
* quiz attempts for course $data->courseid, if $data->reset_quiz_attempts is
* set and true.
*
* Also, move the quiz open and close dates, if the course start date is changing.
*
* @param $data the data submitted from the reset course forum.
* @param $showfeedback whether to output progress information as the reset
* progresses.
*/
function quiz_delete_userdata($data, $showfeedback = true)
{
global $CFG;
/// Delete attempts.
if (!empty($data->reset_quiz_attempts)) {
$conditiononquizids = 'quiz IN (SELECT id FROM ' . $CFG->prefix . 'quiz q WHERE q.course = ' . $data->courseid . ')';
$attemptids = get_records_select('quiz_attempts', $conditiononquizids, '', 'id, uniqueid');
if ($attemptids) {
if ($showfeedback) {
echo '<div class="notifysuccess">', get_string('deletingquestionattempts', 'quiz');
$divider = ': ';
}
foreach ($attemptids as $attemptid) {
delete_attempt($attemptid->uniqueid);
if ($showfeedback) {
echo $divider, $attemptid->uniqueid;
$divider = ', ';
}
}
if ($showfeedback) {
echo "</div><br />\n";
}
}
if (delete_records_select('quiz_grades', $conditiononquizids) && $showfeedback) {
notify(get_string('gradesdeleted', 'quiz'), 'notifysuccess');
}
if (delete_records_select('quiz_attempts', $conditiononquizids) && $showfeedback) {
notify(get_string('attemptsdeleted', 'quiz'), 'notifysuccess');
}
}
/// Update open and close dates
if (!empty($data->reset_start_date)) {
/// Work out offset.
$olddate = get_field('course', 'startdate', 'id', $data->courseid);
$olddate = usergetmidnight($olddate);
// time part of $olddate should be zero
$newdate = make_timestamp($data->startyear, $data->startmonth, $data->startday);
$interval = $newdate - $olddate;
/// Apply it to quizzes with an open or close date.
$success = true;
begin_sql();
$success = $success && execute_sql("UPDATE {$CFG->prefix}quiz\n SET timeopen = timeopen + {$interval}\n WHERE course = {$data->courseid} AND timeopen <> 0", false);
$success = $success && execute_sql("UPDATE {$CFG->prefix}quiz\n SET timeclose = timeclose + {$interval}\n WHERE course = {$data->courseid} AND timeclose <> 0", false);
if ($success) {
commit_sql();
if ($showfeedback) {
notify(get_string('openclosedatesupdated', 'quiz'), 'notifysuccess');
}
} else {
rollback_sql();
}
}
}
示例12: sync_users
//.........这里部分代码省略.........
echo "Searching Context: " . $context . "\n";
begin_sql();
if ($this->config->search_sub) {
//use ldap_search to find first user from subtree
$ldap_result = ldap_search($ldapconnection, $context, $filter, array($this->config->user_attribute));
} else {
//search only in this context
$ldap_result = ldap_list($ldapconnection, $context, $filter, array($this->config->user_attribute));
}
if ($entry = ldap_first_entry($ldapconnection, $ldap_result)) {
do {
$value = ldap_get_values_len($ldapconnection, $entry, $this->config->user_attribute);
$value = $textlib->convert($value[0], $this->config->ldapencoding, 'utf-8');
// usernames are __always__ lowercase.
if (strpos($value[0], '$') && $this->config->user_type == 'ad') {
// Eliminiate AD Service Accounts
continue;
}
// Skip AD Service Account Entries
array_push($fresult, moodle_strtolower($value));
if (count($fresult) >= $bulk_insert_records) {
$this->ldap_bulk_insert($fresult, $temptable);
$fresult = array();
}
} while ($entry = ldap_next_entry($ldapconnection, $entry));
}
unset($ldap_result);
// free mem
// insert any remaining users and release mem
if (count($fresult)) {
$this->ldap_bulk_insert($fresult, $temptable);
$fresult = array();
}
commit_sql();
}
/// preserve our user database
/// if the temp table is empty, it probably means that something went wrong, exit
/// so as to avoid mass deletion of users; which is hard to undo
$count = get_record_sql('SELECT COUNT(username) AS count, 1 FROM ' . $temptable);
$count = $count->{'count'};
if ($count < 1) {
print "Did not get any users from LDAP -- error? -- exiting\n";
exit;
} else {
print "Got {$count} records from LDAP\n\n";
}
/// User removal
// find users in DB that aren't in ldap -- to be removed!
// this is still not as scalable (but how often do we mass delete?)
if (!empty($this->config->removeuser)) {
$sql = "SELECT u.id, u.username, u.email, u.auth\r\n FROM {$CFG->prefix}user u\r\n LEFT JOIN {$temptable} e ON u.username = e.username\r\n AND u.mnethostid = e.mnethostid\r\n WHERE u.auth='ldapsso'\r\n AND u.deleted=0\r\n AND e.username IS NULL";
$remove_users = get_records_sql($sql);
if (!empty($remove_users)) {
print "User entries to remove: " . count($remove_users) . "\n";
foreach ($remove_users as $user) {
if ($this->config->removeuser == 2) {
if (delete_user($user)) {
echo "\t";
print_string('auth_dbdeleteuser', 'auth', array($user->username, $user->id));
echo "\n";
} else {
echo "\t";
print_string('auth_dbdeleteusererror', 'auth', $user->username);
echo "\n";
}
} else {
示例13: dialogue_delete_conversation
function dialogue_delete_conversation($dialogueid, $conversationid)
{
//echo "<div style=\"text-align:center;\">deleting dialogue $dialogueid and conversation $conversationid</div>";
begin_sql();
//$tx = true; // transaction sanity
$tx = delete_records("dialogue_conversations", "id", $conversationid, "dialogueid", $dialogueid);
$tx = $tx && delete_records("dialogue_entries", "conversationid", $conversationid, "dialogueid", $dialogueid);
if ($tx) {
commit_sql();
} else {
rollback_sql();
error("oups...error deleting conversation");
return false;
}
return true;
}
示例14: register_scannedjob
/**
* Process Job's results logged in a text file.
*
* @param array $scan from table blended_scans
*/
function register_scannedjob($scan)
{
global $CFG;
global $scansfoldername;
$jobid = $scan->id;
$fieldspath = blended_getOMRFieldsetDir($scan);
$logfile = blended_getOMRInputLogFilePath($scan);
try {
if ($logfile != 'null') {
$logelements = read_log_file($logfile);
}
if (!isset($logelements) || count($logelements) == 0) {
throw new OMRError("Log file is empty", OMRError::LOG_FILE_IS_EMPTY);
}
} catch (OMRError $e) {
throw $e;
}
// open a transaction
begin_sql();
foreach ($logelements as $logelement) {
try {
//cada elemento es un registro de blended_images.
$image_result = parse_log_elements($logelement);
$image_result->jobid = $jobid;
register_image($image_result);
$acode = $image_result->activitycode;
if ($acode != null) {
if ($acode == 'Undetected') {
mtrace("Undetected activity code for result:" . $logelement);
} else {
mtrace('<br>REGISTERING FIELDS...');
register_template_fields($image_result, $fieldspath);
mtrace('<br>REGISTERING RESULTS...');
register_result_files($image_result, $fieldspath);
mtrace('<br>CHECKING VALIDITY...');
check_invalid_results($image_result);
}
}
} catch (Exception $e) {
mtrace('OMRError: ' . $e->getMessage());
register_exception($e, $jobid);
$errorcode = $e->getCode();
if ($errorcode == 5 or $errorcode == 6) {
//print_object($e);
//throw $e;
continue;
// process next result
}
}
}
mtrace('<br>UPDATING SCANJOB QUEUE...');
update_record('blended_scans', $scan);
// End the transaction
commit_sql();
return;
}
示例15: quiz_upgrade
//.........这里部分代码省略.........
/// Entries for the log_display table
$success = $success && modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'preview', 'quiz', 'name');");
$success = $success && modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'start attempt', 'quiz', 'name');");
$success = $success && modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'close attempt', 'quiz', 'name');");
/// update the default settings in $CFG
$review = QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_RESPONSES + QUIZ_REVIEW_SCORES;
if (!empty($CFG->quiz_feedback)) {
$review += QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK;
}
if (!empty($CFG->quiz_correctanswers)) {
$review += QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS;
}
if (isset($CFG->quiz_review) and $CFG->quiz_review & 1) {
$review += QUIZ_REVIEW_CLOSED;
}
if (isset($CFG->quiz_review) and $CFG->quiz_review & 2) {
$review += QUIZ_REVIEW_OPEN;
}
$success = $success && set_config('quiz_review', $review);
/// Use tolerance instead of min and max in numerical question type
$success = $success && table_column('quiz_numerical', '', 'tolerance', 'varchar', '255', '', '0.0', 'not null', 'question');
$success = $success && execute_sql("UPDATE {$CFG->prefix}quiz_numerical SET tolerance = (max::text::real-min::text::real)/2");
$success = $success && modify_database('', 'ALTER TABLE prefix_quiz_numerical DROP COLUMN min');
// Replaced by tolerance
$success = $success && modify_database('', 'ALTER TABLE prefix_quiz_numerical DROP COLUMN max');
// Replaced by tolerance
/// Tables for Remote Questions
$success = $success && modify_database('', "CREATE TABLE prefix_quiz_rqp (\n id SERIAL PRIMARY KEY,\n question integer NOT NULL default '0',\n type integer NOT NULL default '0',\n source text NOT NULL,\n format varchar(255) NOT NULL default '',\n flags integer NOT NULL default '0',\n maxscore integer NOT NULL default '1'\n );");
$success = $success && modify_database('', "CREATE INDEX prefix_quiz_rqp_question_idx ON prefix_quiz_rqp (question);");
$success = $success && modify_database('', "CREATE TABLE prefix_quiz_rqp_states (\n id SERIAL PRIMARY KEY,\n stateid integer NOT NULL default '0',\n responses text NOT NULL,\n persistent_data text NOT NULL,\n template_vars text NOT NULL\n );");
$success = $success && modify_database('', "CREATE TABLE prefix_quiz_rqp_types (\n id SERIAL PRIMARY KEY,\n name varchar(255) NOT NULL default '',\n rendering_server varchar(255) NOT NULL default '',\n cloning_server varchar(255) NOT NULL default '',\n flags integer NOT NULL default '0'\n );");
$success = $success && modify_database('', "CREATE UNIQUE INDEX prefix_quiz_rqp_types_name_uk ON prefix_quiz_rqp_types (name);");
if ($success) {
$success = $success && commit_sql();
} else {
rollback_sql();
}
}
if ($success && $oldversion < 2005042900 && false) {
// We don't want this to be executed any more!!!
begin_sql();
$success = $success && table_column('quiz_multianswers', '', 'sequence', 'varchar', '255', '', '', 'not null', 'question');
$success = $success && table_column('quiz_numerical', '', 'answers', 'varchar', '255', '', '', 'not null', 'answer');
$success = $success && modify_database('', 'UPDATE prefix_quiz_numerical SET answers = answer');
$success = $success && table_column('quiz_questions', '', 'parent', 'integer', '10', 'unsigned', '0', 'not null', 'category');
$success = $success && modify_database('', "UPDATE prefix_quiz_questions SET parent = id WHERE qtype ='" . RANDOM . "';");
// convert multianswer questions to the new model
if ($multianswers = get_records_sql("SELECT m.id, q.category, q.id AS parent,\n q.name, q.questiontextformat, m.norm AS\n defaultgrade, m.answertype AS qtype,\n q.version, q.hidden, m.answers,\n m.positionkey\n FROM {$CFG->prefix}quiz_questions q,\n {$CFG->prefix}quiz_multianswers m\n WHERE q.qtype = '" . MULTIANSWER . "'\n AND q.id = m.question\n ORDER BY q.id ASC, m.positionkey ASC")) {
$multianswers = array_values($multianswers);
$n = count($multianswers);
$parent = $multianswers[0]->parent;
$sequence = array();
// turn reporting off temporarily to avoid one line output per set_field
$olddebug = $db->debug;
$db->debug = false;
for ($i = 0; $i < $n; $i++) {
$answers = $multianswers[$i]->answers;
unset($multianswers[$i]->answers);
$pos = $multianswers[$i]->positionkey;
unset($multianswers[$i]->positionkey);
// create questions for all the multianswer victims
unset($multianswers[$i]->id);
$multianswers[$i]->length = 0;
$multianswers[$i]->questiontext = '';
$multianswers[$i]->stamp = make_unique_id_code();
$id = insert_record('quiz_questions', $multianswers[$i]);