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); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new CurrencyRates(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['CurrencyRates'])) { $model->attributes = $_POST['CurrencyRates']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }