public function actionCreatePageVersion()
    {
        $name = Yii::$app->request->post('name');
        $fromPageId = (int) Yii::$app->request->post('fromPageId');
        $navItemId = (int) Yii::$app->request->post('navItemId');
        $layoutId = Yii::$app->request->post('layoutId');
        
        if (empty($name) || empty($navItemId)) {
            return ['error' => true];
        }
        
        if (empty($fromPageId) && empty($layoutId)) {
            return ['error' => true];
        }
        
        $navItemModel = NavItem::findOne($navItemId);
        
        if (!$navItemModel) {
            throw new Exception("Unable to find nav item model");
        }
        
        if (!empty($fromPageId)) {
            $fromPageModel = NavItemPage::findOne($fromPageId);
            $layoutId = $fromPageModel->layout_id;
        }
        
        $model = new NavItemPage();
        $model->attributes = [
            'nav_item_id' => $navItemId,
            'timestamp_create' => time(),
            'create_user_id' => Yii::$app->adminuser->getId(),
            'version_alias' => $name,
            'layout_id' => $layoutId,
        ];
        
        $save = $model->save(false);
        
        if (!empty($fromPageId) && $save) {
            NavItemPage::copyBlocks($fromPageModel->id, $model->id);
        }
        
        if (empty($navItemModel->nav_item_type_id) && $navItemModel->nav_item_type == 1) {
            $navItemModel->updateAttributes(['nav_item_type_id' => $model->id]);
        }
        
        $navItemModel->updateAttributes(['timestamp_update' => time()]);
        
        return ['error' => !$save];
    }
public function actionCreatePageVersion()
    {
        $name = Yii::$app->request->post('name');
        $fromPageId = (int) Yii::$app->request->post('fromPageId');
        $navItemId = (int) Yii::$app->request->post('navItemId');
        $layoutId = Yii::$app->request->post('layoutId');
        
        if (empty($name) || empty($navItemId)) {
            return ['error' => true];
        }
        
        if (empty($fromPageId) && empty($layoutId)) {
            return ['error' => true];
        }
        
        $navItemModel = NavItem::findOne($navItemId);
        
        if (!$navItemModel) {
            throw new Exception("Unable to find nav item model");
        }
        
        if (!empty($fromPageId)) {
            $fromPageModel = NavItemPage::findOne($fromPageId);
            $layoutId = $fromPageModel->layout_id;
        }
        
        $model = new NavItemPage();
        $model->attributes = [
            'nav_item_id' => $navItemId,
            'timestamp_create' => time(),
            'create_user_id' => Yii::$app->adminuser->getId(),
            'version_alias' => $name,
            'layout_id' => $layoutId,
        ];
        
        $save = $model->save(false);
        
        if (!empty($fromPageId) && $save) {
            NavItemPage::copyBlocks($fromPageModel->id, $model->id);
        }
        
        if (empty($navItemModel->nav_item_type_id) && $navItemModel->nav_item_type == 1) {
            $navItemModel->updateAttributes(['nav_item_type_id' => $model->id]);
        }
        
        $navItemModel->updateAttributes(['timestamp_update' => time()]);
        
        return ['error' => !$save];
    }
public function actionCreatePageVersion ( ) { $ name = Yii :: $ app -> request -> post ( 'name' ) ; $ fromPageId = ( int ) Yii :: $ app -> request -> post ( 'fromPageId' ) ; $ navItemId = ( int ) Yii :: $ app -> request -> post ( 'navItemId' ) ; $ layoutId = Yii :: $ app -> request -> post ( 'layoutId' ) ; if ( empty ( $ name ) || empty ( $ navItemId ) ) { return [ 'error' => true ] ; } if ( empty ( $ fromPageId ) && empty ( $ layoutId ) ) { return [ 'error' => true ] ; } $ navItemModel = NavItem :: findOne ( $ navItemId ) ; if ( ! $ navItemModel ) { throw new Exception ( "Unable to find nav item model" ) ; } if ( ! empty ( $ fromPageId ) ) { $ fromPageModel = NavItemPage :: findOne ( $ fromPageId ) ; $ layoutId = $ fromPageModel -> layout_id ; } $ model = new NavItemPage ( ) ; $ model -> attributes = [ 'nav_item_id' => $ navItemId , 'timestamp_create' => time ( ) , 'create_user_id' => Yii :: $ app -> adminuser -> getId ( ) , 'version_alias' => $ name , 'layout_id' => $ layoutId , ] ; $ save = $ model -> save ( false ) ; if ( ! empty ( $ fromPageId ) && $ save ) { NavItemPage :: copyBlocks ( $ fromPageModel -> id , $ model -> id ) ; } if ( empty ( $ navItemModel -> nav_item_type_id ) && $ navItemModel -> nav_item_type == 1 ) { $ navItemModel -> updateAttributes ( [ 'nav_item_type_id' => $ model -> id ] ) ; } $ navItemModel -> updateAttributes ( [ 'timestamp_update' => time ( ) ] ) ; return [ 'error' => ! $ save ] ; }
Create a new cms_nav_item_page for an existing nav_item, this is also known as a "new version" of a page item.
Create a new cms_nav_item_page for an existing nav_item this is also known as a new version of a page item .