r95352 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95351‎ | r95352 | r95353 >
Date:23:25, 23 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
implemented delete api module
Modified paths:
  • /trunk/extensions/Survey/Survey.php (modified) (history)
  • /trunk/extensions/Survey/api/ApiDeleteSurvey.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/Survey.php
@@ -58,9 +58,12 @@
5959 $wgAutoloadClasses['SpecialSurveys'] = dirname( __FILE__ ) . '/specials/SpecialSurveys.php';
6060 $wgAutoloadClasses['SpecialSurveyStats'] = dirname( __FILE__ ) . '/specials/SpecialSurveyStats.php';
6161
62 -$wgSpecialPages['SpecialSurveys'] = 'SpecialSurveys';
63 -$wgSpecialPages['SpecialSurveyStats'] = 'SpecialSurveyStats';
 62+$wgSpecialPages['Surveys'] = 'SpecialSurveys';
 63+$wgSpecialPages['SurveyStats'] = 'SpecialSurveyStats';
6464
 65+$wgSpecialPageGroups['Surveys'] = 'other';
 66+$wgSpecialPageGroups['SurveyStats'] = 'other';
 67+
6568 $wgAPIModules['addsurvey'] = 'ApiAddSurvey';
6669 $wgAPIModules['deletesurvey'] = 'ApiDeleteSurvey';
6770 $wgAPIModules['editsurvey'] = 'ApiEditSurvey';
@@ -72,6 +75,20 @@
7376 $wgAvailableRights[] = 'surveyadmin';
7477 $wgAvailableRights[] = 'surveysubmit';
7578
 79+# Users that can manage the surveys.
 80+$wgGroupPermissions['*' ]['surveyadmin'] = false;
 81+$wgGroupPermissions['user' ]['surveyadmin'] = false;
 82+$wgGroupPermissions['autoconfirmed']['surveyadmin'] = false;
 83+$wgGroupPermissions['bot' ]['surveyadmin'] = false;
 84+$wgGroupPermissions['sysop' ]['surveyadmin'] = true;
 85+
 86+# Users that can submit surveys.
 87+$wgGroupPermissions['*' ]['surveysubmit'] = true;
 88+$wgGroupPermissions['user' ]['surveysubmit'] = true;
 89+$wgGroupPermissions['autoconfirmed']['surveysubmit'] = true;
 90+$wgGroupPermissions['bot' ]['surveysubmit'] = false;
 91+$wgGroupPermissions['sysop' ]['surveysubmit'] = true;
 92+
7693 $egSurveyScriptPath = $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath;
7794 $egSurveyScriptPath .= '/Survey/resources';
7895
Index: trunk/extensions/Survey/api/ApiDeleteSurvey.php
@@ -27,32 +27,105 @@
2828
2929 $params = $this->extractRequestParams();
3030
 31+ $everythingOk = true;
 32+
 33+ foreach ( $params['ids'] as $id ) {
 34+ $everythingOk = $this->deleteSurvey( $id ) && $everythingOk;
 35+ }
 36+
 37+ $this->getResult()->addValue(
 38+ null,
 39+ 'success',
 40+ $everythingOk
 41+ );
3142 }
 43+
 44+ /**
 45+ * Delete the survey with provided id.
 46+ *
 47+ * @since 0.1
 48+ *
 49+ * @param integer $id
 50+ *
 51+ * @return boolean Success indicator
 52+ */
 53+ protected function deleteSurvey( $id ) {
 54+ $dbr = wfgetDB( DB_SLAVE );
 55+
 56+ $submissionsForSurvey = $dbr->select(
 57+ 'survey_submissions',
 58+ array( 'submission_id' ),
 59+ array( 'submission_survey_id' => $id )
 60+ );
 61+
 62+ $dbw = wfgetDB( DB_MASTER );
 63+
 64+ $dbw->begin();
 65+
 66+ $everythingOk = $dbw->delete(
 67+ 'surveys',
 68+ array( 'survey_id' => $id )
 69+ );
 70+
 71+ $everythingOk = $dbw->delete(
 72+ 'survey_questions',
 73+ array( 'question_survey_id' => $id )
 74+ ) && $everythingOk;
 75+
 76+ $everythingOk = $dbw->delete(
 77+ 'survey_submissions',
 78+ array( 'submission_survey_id' => $id )
 79+ ) && $everythingOk;
 80+
 81+ foreach ( $submissionsForSurvey as $nr => $submission ) {
 82+ $everythingOk = $dbw->delete(
 83+ 'survey_answers',
 84+ array( 'answer_submission_id' => $submission->submission_id )
 85+ ) && $everythingOk;
 86+
 87+ if ( $nr % 500 == 0 ) {
 88+ $dbw->commit();
 89+ $dbw->begin();
 90+ }
 91+ }
 92+
 93+ $dbw->commit();
 94+
 95+ return $everythingOk;
 96+ }
3297
3398 public function getAllowedParams() {
3499 return array(
 100+ 'ids' => array(
 101+ ApiBase::PARAM_TYPE => 'integer',
 102+ ApiBase::PARAM_REQUIRED => true,
 103+ ApiBase::PARAM_ISMULTI => true,
 104+ ),
35105 );
36106 }
37107
38108 public function getParamDescription() {
39109 return array(
 110+ 'ids' => 'The IDs of the surveys to delete'
40111 );
41112 }
42113
43114 public function getDescription() {
44115 return array(
45 - ''
 116+ 'API module for deleting surveys.'
46117 );
47118 }
48119
49120 public function getPossibleErrors() {
50121 return array_merge( parent::getPossibleErrors(), array(
 122+ array( 'missingparam', 'ids' ),
51123 ) );
52124 }
53125
54126 protected function getExamples() {
55127 return array(
56 - 'api.php?action=deletesurvey&',
 128+ 'api.php?action=deletesurvey&ids=42',
 129+ 'api.php?action=deletesurvey&ids=4|2',
57130 );
58131 }
59132

Status & tagging log