public static function CurrenyRatesUpdate() { ini_set('max_execution_time', 150000); ini_set("memory_limit", "128M"); $max_date_sql = "select MAX(day) day from currency_rates"; $max_date_res = Yii::app()->db->createCommand($max_date_sql)->queryAll(true); //var_dump($max_date_res[0]["day"]); //exit; $start_date = date($max_date_res[0]["day"]); // date("2000-01-01"); // date('Y-m-d', strtotime('-1 years')); $start_date = strtotime($start_date); $start_date = strtotime("+1 day", $start_date); $start_date = date('Y-m-d', $start_date); $currencies = ['EUR', 'JPY', 'GBP', 'AUD', 'CHF', 'CAD', 'MXN', 'CNY', 'CNH', 'NZD', 'SEK', 'RUB', 'DKK', 'NOK', 'HKD', 'SGD', 'TRY', 'KRW', 'ZAR', 'BRL', 'INR']; while (strtotime($start_date) <= strtotime("now")) { $existing_rate = CurrencyRates::model()->findByAttributes(['day' => $start_date]); if (count($existing_rate) == 0) { $currency_rates = new CurrencyRates(); $currency_rates->day = $start_date; foreach ($currencies as $cur) { $currency_rates->{$cur} = 1; $Url = "http://currencies.apps.grandtrunk.net/getrate/" . $start_date . "/" . $cur . "/USD"; $get_rate = Self::url_get_contents($Url); if ($get_rate >= 0) { $currency_rates->{$cur} = $get_rate; } } $currency_rates->save(); } ///+one day// $start_date = strtotime($start_date); $start_date = strtotime("+1 day", $start_date); $start_date = date('Y-m-d', $start_date); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return CurrencyRates the loaded model * @throws CHttpException */ public function loadModel($id) { $model = CurrencyRates::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }