public function execute() { global $wgUser; if ( !$wgUser->isAllowed( 'surveyadmin' ) || $wgUser->isBlocked() ) { $this->dieUsageMsg( array( 'badaccess-groups' ) ); } $params = $this->extractRequestParams(); foreach ( $params['questions'] as &$question ) { $question = SurveyQuestion::newFromUrlData( $question ); } $survey = new Survey( Survey::getValidFields( $params, $params['id'] ) ); $this->getResult()->addValue( null, 'success', $survey->writeToDB() ); $this->getResult()->addValue( 'survey', 'id', $survey->getId() ); $this->getResult()->addValue( 'survey', 'name', $survey->getField( 'name' ) ); }
public function execute() { global $wgUser; if ( !$wgUser->isAllowed( 'surveyadmin' ) || $wgUser->isBlocked() ) { $this->dieUsageMsg( array( 'badaccess-groups' ) ); } $params = $this->extractRequestParams(); foreach ( $params['questions'] as &$question ) { $question = SurveyQuestion::newFromUrlData( $question ); } try { $survey = new Survey( Survey::getValidFields( $params ) ); $success = $survey->writeToDB(); } catch ( DBQueryError $ex ) { if ( $ex->errno == 1062 ) { $this->dieUsage( wfMsgExt( 'survey-err-duplicate-name', 'parsemag', $params['name'] ), 'duplicate-survey-name' ); } else { throw $ex; } } $this->getResult()->addValue( null, 'success', $success ); $this->getResult()->addValue( 'survey', 'id', $survey->getId() ); $this->getResult()->addValue( 'survey', 'name', $survey->getField( 'name' ) ); }