/** * @desc * @requestParam int task_id The ID of the task completed * @responseParam string result OK or completed error * @responseParam int tasks_completed number of tasks completed so far * @responseParam int tasks_remaining number of tasks remaining */ public function doTask() { $wiki_id = $this->wg->CityId; $task_id = $this->request->getVal("task_id"); if (!isset($this->counters[$task_id])) { $this->setVal('result', 'error'); $this->setVal('error', 'invalid task_id'); return; } $isBonusTask = in_array($task_id, $this->bonus_tasks) ? true : false; $response = $this->sendSelfRequest('isTaskComplete', array("task_id" => $task_id)); if (!$isBonusTask && $response->getVal('task_completed', 0) == "1") { $this->setVal('result', 'error'); $this->setVal('error', 'task_completed'); return; } $dbw = $this->getDB(DB_MASTER); $sql = "INSERT INTO founder_progress_bar_tasks \n\t\t\tSET wiki_id={$wiki_id}, \n\t\t\t\ttask_id={$task_id}, \n\t\t\t\ttask_count=1\n\t\t\tON DUPLICATE KEY UPDATE task_count = task_count + 1"; $dbw->query($sql); $res = $dbw->select('founder_progress_bar_tasks', array('task_id', 'task_count'), array('wiki_id' => $wiki_id, 'task_id' => $task_id)); $row = $dbw->fetchRow($res); if (!$row) { // Some kind of crazy error happened? $this->setVal('result', 'error'); $this->setVal('error', 'invalid task_id'); return; } $actions_completed = (int) $row['task_count']; $actions_remaining = $this->counters[$task_id] - $actions_completed; $this->setVal('actions_completed', $actions_completed); $this->setVal('actions_remaining', $actions_remaining); $this->setVal('result', 'OK'); if ($actions_remaining <= 0) { $completedSQL = "task_completed = 1"; // Bonus tasks can be completed more than once if (in_array($task_id, $this->bonus_tasks)) { $completedSQL = "task_completed = task_completed + 1"; } $dbw->update('founder_progress_bar_tasks', array('task_count' => '0', $completedSQL), array('wiki_id' => $wiki_id, 'task_id' => $task_id)); $this->setVal('result', "task_completed"); // Check to see if we got to 100% complete FounderProgressBarHooks::allTasksComplete(true); // Open bonus task if necessary $this->setVal("bonus_tasks_unlocked", $this->openBonusTask()); } $dbw->commit(); // DB update was done, so force refresh of memcache data $this->sendSelfRequest("getLongTaskList", array("use_master" => true)); }
public static function FounderProgressBar($cv_name, $wiki_id, $value) { // Initialize data if extension is enabled. Safe to do multiple times, just gives a warning if ($cv_name == 'wgEnableFounderProgressBarExt' && $value == true) { Wikia::log(__METHOD__, $wiki_id, "{$cv_name} = {$value}"); FounderProgressBarHooks::initRecords($wiki_id); } return true; }