Index: trunk/extensions/Contest/Contest.hooks.php |
— | — | @@ -177,4 +177,44 @@ |
178 | 178 | return true; |
179 | 179 | } |
180 | 180 | |
181 | | -} |
\ No newline at end of file |
| 181 | + /** |
| 182 | + * Called when changing user email address. |
| 183 | + * @see https://www.mediawiki.org/wiki/Manual:Hooks/UserSetEmail |
| 184 | + * |
| 185 | + * Checks if there are any active contests in which the user is participating, |
| 186 | + * and if so, updates the email there as well. |
| 187 | + * |
| 188 | + * @since 0.1 |
| 189 | + * |
| 190 | + * @param User $user |
| 191 | + * @param string $email |
| 192 | + * |
| 193 | + * @return true |
| 194 | + */ |
| 195 | + public static function onUserSetEmail( User $user, &$email ) { |
| 196 | + $dbr = wfGetDB( DB_SLAVE ); |
| 197 | + |
| 198 | + $contestants = $dbr->select( |
| 199 | + array( 'contest_contestants', 'contests' ), |
| 200 | + array( 'contestant_id' ), |
| 201 | + array( 'contest_status' => Contest::STATUS_ACTIVE ), |
| 202 | + '', |
| 203 | + array(), |
| 204 | + array( 'contest_id=contestant_contest_id' ) |
| 205 | + ); |
| 206 | + |
| 207 | + $contestantIds = array(); |
| 208 | + |
| 209 | + foreach ( $contestants as $contestant ) { |
| 210 | + $contestantIds[] = $contestant->contestant_id; |
| 211 | + } |
| 212 | + |
| 213 | + ContestContestant::s()->update( |
| 214 | + array( 'email' => $email ), |
| 215 | + array( 'id' => $contestantIds ) |
| 216 | + ); |
| 217 | + |
| 218 | + return true; |
| 219 | + } |
| 220 | + |
| 221 | +} |
Index: trunk/extensions/Contest/specials/SpecialContestSubmission.php |
— | — | @@ -144,8 +144,10 @@ |
145 | 145 | $contestant = new ContestContestant( array( |
146 | 146 | 'id' => $data['contestant-id'], |
147 | 147 | |
| 148 | + 'full_name' => $data['contestant-realname'], |
| 149 | + 'email' => $data['contestant-email'], |
| 150 | + |
148 | 151 | 'country' => $data['contestant-country'], |
149 | | - |
150 | 152 | 'volunteer' => $data['contestant-volunteer'], |
151 | 153 | 'wmf' => $data['contestant-wmf'], |
152 | 154 | 'cv' => $data['contestant-cv'], |
Index: trunk/extensions/Contest/specials/SpecialContestSignup.php |
— | — | @@ -51,8 +51,8 @@ |
52 | 52 | * |
53 | 53 | * @return true|array |
54 | 54 | */ |
55 | | - public static function handleSubmission( array $data ) { |
56 | | - $user = $GLOBALS['wgUser']; //$this->getUser(); |
| 55 | + public function handleSubmission( array $data ) { |
| 56 | + $user = $this->getUser(); |
57 | 57 | |
58 | 58 | $user->setEmail( $data['contestant-email'] ); |
59 | 59 | $user->setRealName( $data['contestant-realname'] ); |
— | — | @@ -63,8 +63,11 @@ |
64 | 64 | 'user_id' => $user->getId(), |
65 | 65 | 'challenge_id' => $data['contestant-challengeid'], |
66 | 66 | |
| 67 | + 'full_name' => $data['contestant-realname'], |
| 68 | + 'user_name' => $user->getName(), |
| 69 | + 'email' => $data['contestant-email'], |
| 70 | + |
67 | 71 | 'country' => $data['contestant-country'], |
68 | | - |
69 | 72 | 'volunteer' => $data['contestant-volunteer'], |
70 | 73 | 'wmf' => $data['contestant-wmf'], |
71 | 74 | ) ); |
— | — | @@ -156,7 +159,7 @@ |
157 | 160 | protected function showSignupForm( Contest $contest, $challengeId = false ) { |
158 | 161 | $form = new HTMLForm( $this->getFormFields( $contest, $challengeId ), $this->getContext() ); |
159 | 162 | |
160 | | - $form->setSubmitCallback( array( __CLASS__, 'handleSubmission' ) ); |
| 163 | + $form->setSubmitCallback( array( $this, 'handleSubmission' ) ); |
161 | 164 | $form->setSubmitText( wfMsg( 'contest-signup-submit' ) ); |
162 | 165 | |
163 | 166 | if( $form->show() ){ |
Index: trunk/extensions/Contest/Contest.php |
— | — | @@ -101,6 +101,7 @@ |
102 | 102 | // Hooks |
103 | 103 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'ContestHooks::onSchemaUpdate'; |
104 | 104 | $wgHooks['UnitTestsList'][] = 'ContestHooks::registerUnitTests'; |
| 105 | +$wgHooks['UserSetEmail'][] = 'ContestHooks::onUserSetEmail'; |
105 | 106 | |
106 | 107 | // Rights |
107 | 108 | |