src/console/controllers/UpdateController.php
public function actionUserNameToFirstName()
    {
        if (!CmsUser::find()->count()) {
            $this->stdout("Content not found!\n", Console::BOLD);
            return;
        }

        $this->stdout("1. Cms user name normalize!\n", Console::FG_YELLOW);

        /**
         * @var CmsUser $cmsUser
         */
        foreach (CmsUser::find()->orderBy(['id' => SORT_ASC])->each(10) as $cmsUser) {
            $this->stdout("\t User: {$cmsUser->id}\n", Console::FG_YELLOW);

            if (!$cmsUser->_to_del_name) {
                $this->stdout("\t NOT found property: _to_del_name\n", Console::FG_YELLOW);
                continue;
            }

            $name = $cmsUser->_to_del_name;
            $nameData = explode(" ", $name);

            if (isset($nameData[0])) {
                $cmsUser->first_name = trim($nameData[0]);
            }

            if (isset($nameData[1])) {
                $cmsUser->last_name = trim($nameData[1]);
            }

            if (isset($nameData[2])) {
                $cmsUser->patronymic = trim($nameData[2]);
            }


            if ($cmsUser->save()) {
                $this->stdout("\t Updated name: {$cmsUser->name}\n", Console::FG_GREEN);
            } else {
                $this->stdout("\t NOT updated name: {$cmsUser->id}\n", Console::FG_RED);
            }
        }
    }
public function actionUserNameToFirstName()
    {
        if (!CmsUser::find()->count()) {
            $this->stdout("Content not found!\n", Console::BOLD);
            return;
        }

        $this->stdout("1. Cms user name normalize!\n", Console::FG_YELLOW);

        /**
         * @var CmsUser $cmsUser
         */
        foreach (CmsUser::find()->orderBy(['id' => SORT_ASC])->each(10) as $cmsUser) {
            $this->stdout("\t User: {$cmsUser->id}\n", Console::FG_YELLOW);

            if (!$cmsUser->_to_del_name) {
                $this->stdout("\t NOT found property: _to_del_name\n", Console::FG_YELLOW);
                continue;
            }

            $name = $cmsUser->_to_del_name;
            $nameData = explode(" ", $name);

            if (isset($nameData[0])) {
                $cmsUser->first_name = trim($nameData[0]);
            }

            if (isset($nameData[1])) {
                $cmsUser->last_name = trim($nameData[1]);
            }

            if (isset($nameData[2])) {
                $cmsUser->patronymic = trim($nameData[2]);
            }


            if ($cmsUser->save()) {
                $this->stdout("\t Updated name: {$cmsUser->name}\n", Console::FG_GREEN);
            } else {
                $this->stdout("\t NOT updated name: {$cmsUser->id}\n", Console::FG_RED);
            }
        }
    }
public function actionUserNameToFirstName ( ) { if ( ! CmsUser :: find ( ) -> count ( ) ) { $ this -> stdout ( "Content not found!\n" , Console :: BOLD ) ; return ; } $ this -> stdout ( "1. Cms user name normalize!\n" , Console :: FG_YELLOW ) ; /**
         * @var CmsUser $cmsUser
         */ foreach ( CmsUser :: find ( ) -> orderBy ( [ 'id' => SORT_ASC ] ) -> each ( 10 ) as $ cmsUser ) { $ this -> stdout ( "\t User: {$cmsUser->id}\n" , Console :: FG_YELLOW ) ; if ( ! $ cmsUser -> _to_del_name ) { $ this -> stdout ( "\t NOT found property: _to_del_name\n" , Console :: FG_YELLOW ) ; continue ; } $ name = $ cmsUser -> _to_del_name ; $ nameData = explode ( " " , $ name ) ; if ( isset ( $ nameData [ 0 ] ) ) { $ cmsUser -> first_name = trim ( $ nameData [ 0 ] ) ; } if ( isset ( $ nameData [ 1 ] ) ) { $ cmsUser -> last_name = trim ( $ nameData [ 1 ] ) ; } if ( isset ( $ nameData [ 2 ] ) ) { $ cmsUser -> patronymic = trim ( $ nameData [ 2 ] ) ; } if ( $ cmsUser -> save ( ) ) { $ this -> stdout ( "\t Updated name: {$cmsUser->name}\n" , Console :: FG_GREEN ) ; } else { $ this -> stdout ( "\t NOT updated name: {$cmsUser->id}\n" , Console :: FG_RED ) ; } } }
Update user name to first and last name
Update user name to first and last name