src/console/controllers/UtilsController.php
public function actionRemoveContentElements($contentId = null)
    {
        $query = CmsContentElement::find();
        if ($contentId) {
            $query->andWhere(['content_id' => $contentId]);
        }

        if (!$count = $query->count()) {
            $this->stdout("Content elements not found!\n", Console::BOLD);
            return;
        }

        $this->stdout("1. Found elements: {$count}!\n", Console::BOLD);

        foreach ($query->orderBy([
            'content_id' => SORT_ASC,
            'id' => SORT_ASC
        ])->each(10) as $cmsContentElement) {
            $this->stdout("\t{$cmsContentElement->id}: {$cmsContentElement->name}");

            if ($cmsContentElement->delete()) {
                $this->stdout(" - deleted\n", Console::FG_GREEN);
            } else {
                $this->stdout(" - NOT deleted\n", Console::FG_RED);
            }
        }
    }
public function actionRemoveContentElements($contentId = null)
    {
        $query = CmsContentElement::find();
        if ($contentId) {
            $query->andWhere(['content_id' => $contentId]);
        }

        if (!$count = $query->count()) {
            $this->stdout("Content elements not found!\n", Console::BOLD);
            return;
        }

        $this->stdout("1. Found elements: {$count}!\n", Console::BOLD);

        foreach ($query->orderBy([
            'content_id' => SORT_ASC,
            'id' => SORT_ASC
        ])->each(10) as $cmsContentElement) {
            $this->stdout("\t{$cmsContentElement->id}: {$cmsContentElement->name}");

            if ($cmsContentElement->delete()) {
                $this->stdout(" - deleted\n", Console::FG_GREEN);
            } else {
                $this->stdout(" - NOT deleted\n", Console::FG_RED);
            }
        }
    }
public function actionRemoveContentElements ( $ contentId = null ) { $ query = CmsContentElement :: find ( ) ; if ( $ contentId ) { $ query -> andWhere ( [ 'content_id' => $ contentId ] ) ; } if ( ! $ count = $ query -> count ( ) ) { $ this -> stdout ( "Content elements not found!\n" , Console :: BOLD ) ; return ; } $ this -> stdout ( "1. Found elements: {$count}!\n" , Console :: BOLD ) ; foreach ( $ query -> orderBy ( [ 'content_id' => SORT_ASC , 'id' => SORT_ASC ] ) -> each ( 10 ) as $ cmsContentElement ) { $ this -> stdout ( "\t{$cmsContentElement->id}: {$cmsContentElement->name}" ) ; if ( $ cmsContentElement -> delete ( ) ) { $ this -> stdout ( " - deleted\n" , Console :: FG_GREEN ) ; } else { $ this -> stdout ( " - NOT deleted\n" , Console :: FG_RED ) ; } } }
Deleting content items

@param null $contentId content id
Deleting content items