MDL-18293 $DB->somethiong is using exceptions, no need for ifs tehre, removing useless strings

This commit is contained in:
skodak
2009-06-03 20:00:08 +00:00
parent 6aa104ed96
commit bf8e93d704
14 changed files with 16 additions and 61 deletions
+1 -3
View File
@@ -70,9 +70,7 @@ if ($mform->is_cancelled()) {
} else {
// Create a new category.
$newcategory->sortorder = 999;
if (!$newcategory->id = $DB->insert_record('course_categories', $newcategory)) {
print_error('cannotcreatecategory', '', '', format_string($newcategory->name));
}
$newcategory->id = $DB->insert_record('course_categories', $newcategory);
$newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
mark_context_dirty($newcategory->context->path);
fix_course_sortorder(); // Required to build course_categories.depth and .path.
+3 -9
View File
@@ -423,19 +423,13 @@
$fromform->instance = $returnfromfunc;
if (!$DB->set_field('course_modules', 'instance', $returnfromfunc, array('id'=>$fromform->coursemodule))) {
print_error('cannotaddcoursemodule');
}
$DB->set_field('course_modules', 'instance', $returnfromfunc, array('id'=>$fromform->coursemodule));
// course_modules and course_sections each contain a reference
// to each other, so we have to update one of them twice.
if (!$sectionid = add_mod_to_section($fromform)) {
print_error('cannotaddcmtosection');
}
$sectionid = add_mod_to_section($fromform);
if (!$DB->set_field('course_modules', 'section', $sectionid, array('id'=>$fromform->coursemodule))) {
print_error('cannotupdatecm');
}
$DB->set_field('course_modules', 'section', $sectionid, array('id'=>$fromform->coursemodule));
// make sure visibility is set correctly (in particular in calendar)
set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
-14
View File
@@ -13,15 +13,12 @@ $string['blockcannotconfig'] = 'This block does not support global configuration
$string['blocknameconflict'] = 'Naming conflict: block $a->name has the same title with an existing block: $a->conflict!';
$string['backupcontainexternal'] = 'This backup file contains external Moodle Network Hosts that are not configured locally';
$string['backuptablefail'] = 'Backup tables could NOT be set up successfully!';
$string['cannotaddblock'] = '$a block could not be added to the block list!';
$string['cannotaddcoursemodule'] = 'Could not add a new course module';
$string['cannotaddcoursemoduletosection'] = 'Could not add the new course module to that section';
$string['cannotaddcmtosection'] = 'Could not add the new course module to that section';
$string['cannotaddrss'] = 'You do not have permission to add rss feeds';
$string['cannotaddmembergroupiddoesntexist'] = 'Cannot add member group: the group id doesn\'t exist';
$string['cannotaddmodule'] = '$a module could not be added to the module list!';
$string['cannotaddnewmodule'] = 'Could not add a new module of $a';
$string['cannotaddnewinstance'] = 'Could not add a new instance of $a';
$string['cannotassignanthing'] = 'Cannot assign moodle/site:doanything';
$string['cannotassignrole'] = 'Cannot assign role in course';
$string['cannotassignrolehere'] = 'You are not allowed to assign this role (id = $a->roleid) in this context ($a->context)';
@@ -30,11 +27,9 @@ $string['cannotcallusgetselecteduser'] = 'You cannot called user_selector::get_s
$string['cannotcallscript'] = 'You cannot call this script in that way';
$string['cannotcreatebackupdir'] = 'Could not create backupdata folder. The site administrator needs to fix the file permissions';
$string['cannotcreatecategory'] = 'The category was not inserted';
$string['cannotcreatedefaultcat'] = 'Error creating a default category for context $a';
$string['cannotcreategroup'] = 'Error creating group';
$string['cannotcreatelangdir'] = 'Cannot create lang directory';
$string['cannotcreatelangbase'] = 'Error: Could not create base lang directory';
$string['cannotcreatefield'] = 'Error creating new field';
$string['cannotcreatetempdir'] = 'Cannot create temp directory';
$string['cannotcreatesitedir'] = 'Cannot create site folder. The site administrator needs to fix the file permissions.';
$string['cannotcreateuploaddir'] = 'Cannot create upload folder. The site administrator needs to fix the file permissions.';
@@ -45,8 +40,6 @@ $string['cannotcustomisefiltersblockuser'] = 'You cannot customise filters setti
$string['cannotcustomizelocallang'] = 'You do not have permission to customize the strings translation. This permission is controlled by the capability \"moodle/site:langeditlocal\". Set this capability to allow you to edit local language packages in case you want to modify translations for your site.';
$string['cannotdeletelangcache'] = 'Language cache cannot be deleted, please fix permissions in dataroot/cache/languages!';
$string['cannotdeletebackupids'] = 'Couldn\'t delete previous backup ids';
$string['cannotdeletecap'] = 'Could not delete deprecated capability $a';
$string['cannotdeletecate'] = 'Error while deleting category';
$string['cannotdeletecategorycourse'] = 'Course \'$a\' failed to be deleted.';
$string['cannotdeletecategoryquestions'] = 'Could not delete questions from category \'$a\'';
$string['cannotdeletecourse'] = 'You do not have the permission to delete this course';
@@ -132,20 +125,13 @@ $string['cannotsetupcapforplugin'] = 'Could not set up the capabilities for $a';
$string['cannotsetupcapformod'] = 'Could not set up the capabilities for $a';
$string['cannotshowhidecoursesincategory'] = 'Cannot show/hide the courses in category $a.';
$string['cannotunzipfile'] = 'Cannot unzip file';
$string['cannotupdatecm'] = 'Could not update the course module with the correct section';
$string['cannotupdategroup'] = 'Error updating group';
$string['cannotupdaterate'] = 'Could not update an old rating ($a->id = $a->rating)';
$string['cannotupdaterecord'] = 'Could not update record ID $a';
$string['cannotupdaterole'] = 'Cannot update role!';
$string['cannotupdatemod'] = 'Could not update $a';
$string['cannotupdatemodcap'] = 'Could not update $a capabilities!';
$string['cannotupdateuser'] = 'Updating user failed';
$string['cannotupdateusermsgpref'] = 'Cannot update user message preferences';
$string['cannotupdateuseronexauth'] = 'Failed to update user data on external auth: $a. See the server logs for more details.';
$string['cannotupdatepasswordonextauth'] = 'Failed to update password on external auth: $a. See the server logs for more details.';
$string['cannotupdateplugincap'] = 'Could not update $a capabilities!';
$string['cannotupdateprofile'] = 'Error updating user record';
$string['cannotupdatecustomprofile'] = 'Error updating user custom record';
$string['cannotupdaterss'] = 'Cannot update RSS';
$string['cannotupdatesecret'] = 'Error resetting user secret string';
$string['cannotupdatesubcate'] = 'Could not update a child category!';
+2 -5
View File
@@ -3512,11 +3512,8 @@ function capabilities_cleanup($component, $newcapdef=NULL) {
array_key_exists($cachedcap->name, $newcapdef) === false) {
// Remove from capabilities cache.
if (!$DB->delete_records('capabilities', array('name'=>$cachedcap->name))) {
print_error('cannotdeletecap', '', '', $cachedcap->name);
} else {
$removedcount++;
}
$DB->delete_records('capabilities', array('name'=>$cachedcap->name));
$removedcount++;
// Delete from roles.
if ($roles = get_roles_with_capability($cachedcap->name)) {
foreach($roles as $role) {
+1 -3
View File
@@ -2458,9 +2458,7 @@ function question_make_default_categories($contexts) {
$category->parent = 0;
$category->sortorder = 999; // By default, all categories get this number, and are sorted alphabetically.
$category->stamp = make_unique_id_code();
if (!$category->id = $DB->insert_record('question_categories', $category)) {
print_error('cannotcreatedefaultcat', '', '', print_context_name($context));
}
$category->id = $DB->insert_record('question_categories', $category);
} else {
$category = question_get_default_category($context->id);
}
+1 -3
View File
@@ -106,9 +106,7 @@ class filelib_test extends UnitTestCaseUsingDatabase {
$newcategory = new stdClass();
$newcategory->name = 'test category';
$newcategory->sortorder = 999;
if (!$newcategory->id = $DB->insert_record('course_categories', $newcategory)) {
print_error('cannotcreatecategory', '', '', format_string($newcategory->name));
}
$newcategory->id = $DB->insert_record('course_categories', $newcategory);
$newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
mark_context_dirty($newcategory->context->path);
+1 -3
View File
@@ -71,9 +71,7 @@
} else if ($rating != $oldrating->rating) {
$oldrating->rating = $rating;
if (!$DB->update_record('data_ratings', $oldrating)) {
print_error('cannotupdaterate', 'error', '', (object)array('id'=>$record->id, 'rating'=>$rating));
}
$DB->update_record('data_ratings', $oldrating);
data_update_grades($data, $record->userid);
}
+1 -3
View File
@@ -79,9 +79,7 @@
if ($rating != $oldrating->rating) {
$oldrating->rating = $rating;
$oldrating->time = time();
if (!$DB->update_record('forum_ratings', $oldrating)) {
print_error('cannotupdaterate', 'error', '', (object)array('id'=>$post->id, 'rating'=>$rating));
}
$DB->update_record('forum_ratings', $oldrating);
forum_update_grades($forum, $post->userid);
}
+1 -3
View File
@@ -626,9 +626,7 @@ function hotpot_add_chain(&$hotpot) {
hotpot_set_name_summary_reference($hotpot, $i);
$hotpot->reference = $hotpot->reference;
if (!$hotpot->instance = $DB->insert_record("hotpot", $hotpot)) {
print_error('cannotaddnewinstance', '', 'view.php?id='.$hotpot->course, $hotpot->modulename);
}
$hotpot->instance = $DB->insert_record("hotpot", $hotpot);
// store (hotpot table) id of start of chain
if ($i==0) {
+1 -3
View File
@@ -78,9 +78,7 @@ function scorm_add_instance($scorm, $mform=null) {
}
/// update course module record - from now on this instance properly exists and all function may be used
if (!$DB->set_field('course_modules', 'instance', $id, array('id'=>$cmid))) {
print_error('cannotaddcoursemodule');
}
$DB->set_field('course_modules', 'instance', $id, array('id'=>$cmid));
/// reload scorm instance
$scorm = $DB->get_record('scorm', array('id'=>$id));
+1 -3
View File
@@ -407,9 +407,7 @@ class qformat_default {
$category->parent = $parent;
$category->sortorder = 999;
$category->stamp = make_unique_id_code();
if (!($id = $DB->insert_record('question_categories', $category))) {
print_error("cannotcreatecategory");
}
$id = $DB->insert_record('question_categories', $category);
$category->id = $id;
$parent = $id;
}
+1 -3
View File
@@ -135,9 +135,7 @@
$usernew->timemodified = time();
if (!$DB->update_record('user', $usernew)) {
print_error('cannotupdateprofile');
}
$DB->update_record('user', $usernew);
// pass a true $userold here
if (! $authplugin->user_update($user, $userform->get_data())) {
+1 -3
View File
@@ -266,9 +266,7 @@ function profile_delete_category($id) {
}
/// Finally we get to delete the category
if (!$DB->delete_records('user_info_category', array('id'=>$category->id))) {
print_error('cannotdeletecate');
}
$DB->delete_records('user_info_category', array('id'=>$category->id));
profile_reorder_categories();
return true;
}
+1 -3
View File
@@ -113,9 +113,7 @@ class profile_field_base {
if ($dataid = $DB->get_field('user_info_data', 'id', array('userid'=>$data->userid, 'fieldid'=>$data->fieldid))) {
$data->id = $dataid;
if (!$DB->update_record('user_info_data', $data)) {
print_error('cannotupdatecustomprofile');
}
$DB->update_record('user_info_data', $data);
} else {
$DB->insert_record('user_info_data', $data);
}