private function mapUpdateSplatfest() { if (!$this->needUpdateSplatfest()) { return; } echo "splatfest...\n"; $json = $this->queryJson('http://splapi.retrorocket.biz/fes'); foreach ($json->result as $data) { $start_at = strtotime($data->start); $end_at = strtotime($data->end); $t = gmdate('Y-m-d\\TH:i:sP', (int) (($start_at + $end_at) / 2)); $fest = Splatfest::find()->innerJoinWith('region', false)->andWhere(['and', ['{{region}}.[[key]]' => 'jp'], ['<=', '{{splatfest}}.[[start_at]]', $t], ['>', '{{splatfest}}.[[end_at]]', $t]])->one(); if (!$fest) { continue; } if ($fest->getSplatfestMaps()->count() > 0) { continue; } echo "new data for [" . $fest->name . "]\n"; if (!($maps = SplapiMap::findAll(['name' => $data->maps]))) { echo " no map data available...\n"; continue; } foreach ($maps as $map) { $o = new SplatfestMap(); $o->attributes = ['splatfest_id' => $fest->id, 'map_id' => $map->map_id]; if (!$o->save()) { throw new \Exception('Save failed'); } } } }