本文整理汇总了PHP中rollback_sql函数的典型用法代码示例。如果您正苦于以下问题:PHP rollback_sql函数的具体用法?PHP rollback_sql怎么用?PHP rollback_sql使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rollback_sql函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: quiz_set_grade
/**
* The quiz grade is the score that student's results are marked out of. When it
* changes, the corresponding data in quiz_grades and quiz_feedback needs to be
* rescaled.
*
* @param float $newgrade the new maximum grade for the quiz.
* @param object $quiz the quiz we are updating. Passed by reference so its grade field can be updated too.
* @return boolean indicating success or failure.
*/
function quiz_set_grade($newgrade, &$quiz)
{
// This is potentially expensive, so only do it if necessary.
if (abs($quiz->grade - $newgrade) < 1.0E-7) {
// Nothing to do.
return true;
}
// Use a transaction, so that on those databases that support it, this is safer.
begin_sql();
// Update the quiz table.
$success = set_field('quiz', 'grade', $newgrade, 'id', $quiz->instance);
// Rescaling the other data is only possible if the old grade was non-zero.
if ($quiz->grade > 1.0E-7) {
global $CFG;
$factor = $newgrade / $quiz->grade;
$quiz->grade = $newgrade;
// Update the quiz_grades table.
$timemodified = time();
$success = $success && execute_sql("\n UPDATE {$CFG->prefix}quiz_grades\n SET grade = {$factor} * grade, timemodified = {$timemodified}\n WHERE quiz = {$quiz->id}\n ", false);
// Update the quiz_feedback table.
$success = $success && execute_sql("\n UPDATE {$CFG->prefix}quiz_feedback\n SET mingrade = {$factor} * mingrade, maxgrade = {$factor} * maxgrade\n WHERE quizid = {$quiz->id}\n ", false);
}
// update grade item and send all grades to gradebook
quiz_grade_item_update($quiz);
quiz_update_grades($quiz);
if ($success) {
return commit_sql();
} else {
rollback_sql();
return false;
}
}
示例2: 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;
}
}
示例3: object
}
} else {
$notice = new object();
if (!($notice->id = insert_record('webinar_notice', $todb))) {
rollback_sql();
print_error('error:couldnotaddnotice', 'webinar', $returnurl);
}
}
foreach ($customfields as $field) {
$fieldname = "custom_{$field->shortname}";
if (empty($fromform->{$fieldname})) {
$fromform->{$fieldname} = '';
// need to be able to clear fields
}
if (!webinar_save_customfield_value($field->id, $fromform->{$fieldname}, $notice->id, 'notice')) {
rollback_sql();
print_error('error:couldnotsavecustomfield', 'webinar', $returnurl);
}
}
commit_sql();
redirect($returnurl);
} elseif ($notice != null) {
// Edit mode
// Set values for the form
$toform = new object();
$toform->name = $notice->name;
$toform->text = $notice->text;
foreach ($customfields as $field) {
$fieldname = "custom_{$field->shortname}";
$toform->{$fieldname} = webinar_get_customfield_value($field, $notice->id, 'notice');
}
示例4: 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;
}
示例5: 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;
}
示例6: 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';
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');
}
}
// 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);
// mark internal user record as "deleted"
$updateuser = new object();
$updateuser->id = $user->id;
$updateuser->deleted = 1;
$updateuser->username = addslashes("{$user->email}." . time());
// Remember it just in case
$updateuser->email = '';
// Clear this field to free it up
$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);
return true;
} else {
rollback_sql();
return false;
}
}
示例7: 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);
}
示例8: quiz_upgrade
//.........这里部分代码省略.........
$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]);
$success = $success && $id;
$sequence[$pos] = $id;
示例9: 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();
}
}
}
示例10: 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;
}
示例11: 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;
}
示例12: process_queue
/**
* Fetch a record from the rollover queue and process it.
*
* @param int $id The ID of the request to process.
* @return bool True on success, False otherwise.
*/
function process_queue($id = FALSE)
{
global $CFG, $USER;
require_once $CFG->dirroot . '/message/lib.php';
begin_sql();
if ($id) {
$task = get_record('block_admin_rollover_queue', 'id', $id);
if (!$task) {
commit_sql();
notify(get_string('queue_notfound', 'rollover'), 'notifyproblem errorbox');
return FALSE;
}
} else {
$task = get_record('block_admin_rollover_queue', '', '');
if (!$task) {
commit_sql();
return FALSE;
}
}
print_heading(get_string('run_queue_record', 'rollover', $task));
flush();
// make sure we don't have multiple entries for the course
$status = delete_records('block_admin_course_template', 'courseid', $task->courseid);
$status = $status && delete_records('block_admin_rollover_queue', 'id', $task->id);
$status = $status && content_rollover($task->templateid, $task->courseid);
$trec = new stdClass();
$trec->courseid = $task->courseid;
$trec->templateid = $task->templateid;
$trec->timemodified = time();
$status = $status && ($trec->id = insert_record('block_admin_course_template', $trec));
if ($status) {
commit_sql();
$touser = get_record('user', 'id', $task->userid);
$coursename = get_field('course', 'fullname', 'id', $task->courseid);
$a = new stdClass();
$a->coursename = get_field('course', 'fullname', 'id', $task->courseid);
$a->link = '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $task->courseid . '">' . $coursename . '</a>';
print_heading(get_string('rollover_message', 'rollover', $a));
message_post_message($USER, $touser, get_string('rollover_message', 'rollover', $a), FORMAT_HTML, 'direct');
notify(get_string('success'), 'notifysuccess');
return TRUE;
} else {
rollback_sql();
notify(get_string('rollover_failure', 'rollover'), 'notifyproblem errorbox');
return FALSE;
}
}