Commit e670a5fd authored by Олег Гиммельшпах's avatar Олег Гиммельшпах

Merge branch 'master' of git.task-on.com:ktask/taskoncom

parents 36b41e74 e3c9763e
<?php
namespace console\controllers;
use Yii;
use common\modules\blog\models\PostLang;
use yii\console\Controller;
use yii\web\ServerErrorHttpException;
class ReplaceController extends Controller
{
public function actionBlog()
{
$data = PostLang::find()->all();
$transaction = Yii::$app->db->beginTransaction();
try
{
foreach($data as $i=>$item)
{
$item->text = str_replace('http://task-on.com/', 'https://task-on.com/', $item->text);
if (!$item->save())
{
throw new ServerErrorHttpException(current(current($item->getErrors())));
}
echo ($i+1)." of ".count($data)." successfully updated\n";
}
$transaction->commit();
}
catch(\Exception $e)
{
echo "[".$e->getCode()."]".$e->getMessage();
echo "\n";
$transaction->rollback();
}
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment