sites = $sites; foreach ( $reports as $report ) { $this->reports[ $report->id() ] = $report; } } /** * Warms every site. Google API errors are ignored; the report screen shows them. * * @return void */ public function warm_all() { foreach ( $this->sites->all() as $site ) { $this->warm( $site ); } } /** * Warms one site's opening view. * * @param Profile $site Site. * @return void */ public function warm( Profile $site ) { $p = Periods::default_period(); $t = Periods::trend( $p['e'] ); $calls = array( array( 'search-console', array( 'dimension' => 'date', 'start' => $p['s'], 'end' => $p['e'], ), ), array( 'search-console', array( 'dimension' => 'date', 'start' => $p['ps'], 'end' => $p['pe'], ), ), array( 'search-console', array( 'dimension' => 'page', 'start' => $p['s'], 'end' => $p['e'], ), ), array( 'search-console', array( 'dimension' => 'page', 'start' => $p['ps'], 'end' => $p['pe'], ), ), array( 'search-console', array( 'dimension' => 'query', 'start' => $p['s'], 'end' => $p['e'], ), ), array( 'search-console', array( 'dimension' => 'query', 'start' => $p['ps'], 'end' => $p['pe'], ), ), array( 'search-console', array( 'dimension' => 'date', 'start' => $t['s'], 'end' => $t['e'], ), ), array( 'segments', array( 'start' => $p['s'], 'end' => $p['e'], 'prev_start' => $p['ps'], 'prev_end' => $p['pe'], ), ), array( 'conversions', array( 'kind' => 'totals', 'start' => $p['s'], 'end' => $p['e'], ), ), array( 'conversions', array( 'kind' => 'totals', 'start' => $p['ps'], 'end' => $p['pe'], ), ), array( 'conversions', array( 'kind' => 'pages', 'start' => $p['s'], 'end' => $p['e'], ), ), array( 'conversions', array( 'kind' => 'pages', 'start' => $p['ps'], 'end' => $p['pe'], ), ), array( 'conversions', array( 'kind' => 'daily', 'start' => $p['s'], 'end' => $p['e'], ), ), array( 'conversions', array( 'kind' => 'monthly', 'start' => $t['s'], 'end' => $t['e'], ), ), array( 'ai-traffic', array( 'start' => $p['s'], 'end' => $p['e'], 'prev_start' => $p['ps'], 'prev_end' => $p['pe'], ), ), array( 'traffic', array( 'start' => $p['s'], 'end' => $p['e'], 'prev_start' => $p['ps'], 'prev_end' => $p['pe'], ), ), array( 'business-profile', array( 'start' => min( $p['ps'], $t['s'] ), 'end' => $p['e'], ), ), ); foreach ( $calls as $call ) { list( $id, $params ) = $call; if ( ! isset( $this->reports[ $id ] ) || ! $site->wants( $this->reports[ $id ]->section() ) ) { continue; } try { $this->reports[ $id ]->run( $site, array_merge( array( 'segment' => '' ), $params ) ); } catch ( ApiException $e ) { // An expired sign-in would fail every remaining call; skip the rest of this site. if ( ApiException::RECONNECT === $e->reason() ) { return; } } } } }