Skip to content

Commit

Permalink
MDL-18293 $DB->somethiong is using exceptions, no need for ifs tehre,…
Browse files Browse the repository at this point in the history
… removing useless strings
  • Loading branch information
skodak committed Jun 3, 2009
1 parent 6aa104e commit bf8e93d
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 61 deletions.
4 changes: 1 addition & 3 deletions course/editcategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@
} 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.
Expand Down
12 changes: 3 additions & 9 deletions course/modedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 0 additions & 14 deletions lang/en_utf8/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
$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)';
Expand All @@ -30,11 +27,9 @@
$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.';
Expand All @@ -45,8 +40,6 @@
$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';
Expand Down Expand Up @@ -132,20 +125,13 @@
$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!';
Expand Down
7 changes: 2 additions & 5 deletions lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions lib/questionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 1 addition & 3 deletions lib/simpletest/testfilelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ public function setup() {
$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);
Expand Down
4 changes: 1 addition & 3 deletions mod/data/rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Expand Down
4 changes: 1 addition & 3 deletions mod/forum/rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 1 addition & 3 deletions mod/hotpot/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions mod/scorm/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 1 addition & 3 deletions question/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,7 @@ function create_category_path($catpath, $delimiter='/') {
$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;
}
Expand Down
4 changes: 1 addition & 3 deletions user/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down
4 changes: 1 addition & 3 deletions user/profile/definelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions user/profile/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ function edit_save_data($usernew) {

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);
}
Expand Down

0 comments on commit bf8e93d

Please sign in to comment.