private function checksPageTable()
    {
        $schemaManager = $this->em->getConnection()->getSchemaManager();
        $tableName = $this->em->getClassMetadata('BackBee\NestedNode\Page')->getTableName();

        $this->output->write(sprintf(' - Existing table `%s` - ', $tableName));

        if (false === $schemaManager->tablesExist([$tableName])) {
            $this->output->writeln("<error>Failed</error>");
            throw new BBException(sprintf('Unknown table `%s`, please run BackBee installation script.', $tableName));
        }

        $sectionMeta = $this->em->getClassMetadata('BackBee\NestedNode\Section');
        $this->requiredFields['uid'] = $sectionMeta->getColumnName('_uid');
        $this->requiredFields['leftnode'] = $sectionMeta->getColumnName('_leftnode');
        $this->requiredFields['rightnode'] = $sectionMeta->getColumnName('_rightnode');
        $this->requiredFields['level'] = $sectionMeta->getColumnName('_level');
        $this->requiredFields['created'] = $sectionMeta->getColumnName('_created');
        $this->requiredFields['modified'] = $sectionMeta->getColumnName('_modified');
        $this->requiredFields['site_uid'] = $sectionMeta->getSingleAssociationJoinColumnName('_site');
        $this->requiredFields['root_uid'] = $sectionMeta->getSingleAssociationJoinColumnName('_root');
        $this->requiredFields['parent_uid'] = $sectionMeta->getSingleAssociationJoinColumnName('_parent');

        $existingFields = array_keys($schemaManager->listTableColumns($tableName));
        $missingFields = array_diff($this->requiredFields, $existingFields);

        if (0 < count($missingFields)) {
            $this->output->writeln("<error>Failed</error>");
            throw new BBException(sprintf(
                    'Following required fields are missing in table `%s`: `%s`.%s Cannot upgrade database storage anymore.', 
                    $tableName, 
                    implode('`, `', $missingFields), PHP_EOL)
                );
        }

        $pageMeta = $this->em->getClassMetadata('BackBee\NestedNode\Page');
        $tablePage = $pageMeta->getTableName();
        $sectionField = $pageMeta->getSingleAssociationJoinColumnName('_section');
        if (!in_array($sectionField, $existingFields)) {
            $this->em->getConnection()->executeUpdate(sprintf('ALTER TABLE %s ADD COLUMN %s CHAR(32)', $tablePage, $sectionField));
        }
        $positionField = $pageMeta->getColumnName('_position');
        if (!in_array($positionField, $existingFields)) {
            $this->em->getConnection()->executeUpdate(sprintf('ALTER TABLE %s ADD COLUMN %s INT', $tablePage, $positionField));
        }

        $this->output->writeln('<info>OK</info>');
        return $this;
    }
private function checksPageTable()
    {
        $schemaManager = $this->em->getConnection()->getSchemaManager();
        $tableName = $this->em->getClassMetadata('BackBee\NestedNode\Page')->getTableName();

        $this->output->write(sprintf(' - Existing table `%s` - ', $tableName));

        if (false === $schemaManager->tablesExist([$tableName])) {
            $this->output->writeln("<error>Failed</error>");
            throw new BBException(sprintf('Unknown table `%s`, please run BackBee installation script.', $tableName));
        }

        $sectionMeta = $this->em->getClassMetadata('BackBee\NestedNode\Section');
        $this->requiredFields['uid'] = $sectionMeta->getColumnName('_uid');
        $this->requiredFields['leftnode'] = $sectionMeta->getColumnName('_leftnode');
        $this->requiredFields['rightnode'] = $sectionMeta->getColumnName('_rightnode');
        $this->requiredFields['level'] = $sectionMeta->getColumnName('_level');
        $this->requiredFields['created'] = $sectionMeta->getColumnName('_created');
        $this->requiredFields['modified'] = $sectionMeta->getColumnName('_modified');
        $this->requiredFields['site_uid'] = $sectionMeta->getSingleAssociationJoinColumnName('_site');
        $this->requiredFields['root_uid'] = $sectionMeta->getSingleAssociationJoinColumnName('_root');
        $this->requiredFields['parent_uid'] = $sectionMeta->getSingleAssociationJoinColumnName('_parent');

        $existingFields = array_keys($schemaManager->listTableColumns($tableName));
        $missingFields = array_diff($this->requiredFields, $existingFields);

        if (0 < count($missingFields)) {
            $this->output->writeln("<error>Failed</error>");
            throw new BBException(sprintf(
                    'Following required fields are missing in table `%s`: `%s`.%s Cannot upgrade database storage anymore.', 
                    $tableName, 
                    implode('`, `', $missingFields), PHP_EOL)
                );
        }

        $pageMeta = $this->em->getClassMetadata('BackBee\NestedNode\Page');
        $tablePage = $pageMeta->getTableName();
        $sectionField = $pageMeta->getSingleAssociationJoinColumnName('_section');
        if (!in_array($sectionField, $existingFields)) {
            $this->em->getConnection()->executeUpdate(sprintf('ALTER TABLE %s ADD COLUMN %s CHAR(32)', $tablePage, $sectionField));
        }
        $positionField = $pageMeta->getColumnName('_position');
        if (!in_array($positionField, $existingFields)) {
            $this->em->getConnection()->executeUpdate(sprintf('ALTER TABLE %s ADD COLUMN %s INT', $tablePage, $positionField));
        }

        $this->output->writeln('<info>OK</info>');
        return $this;
    }
private function checksPageTable ( ) { $ schemaManager = $ this -> em -> getConnection ( ) -> getSchemaManager ( ) ; $ tableName = $ this -> em -> getClassMetadata ( 'BackBee\NestedNode\Page' ) -> getTableName ( ) ; $ this -> output -> write ( sprintf ( ' - Existing table `%s` - ' , $ tableName ) ) ; if ( false === $ schemaManager -> tablesExist ( [ $ tableName ] ) ) { $ this -> output -> writeln ( "<error>Failed</error>" ) ; throw new BBException ( sprintf ( 'Unknown table `%s`, please run BackBee installation script.' , $ tableName ) ) ; } $ sectionMeta = $ this -> em -> getClassMetadata ( 'BackBee\NestedNode\Section' ) ; $ this -> requiredFields [ 'uid' ] = $ sectionMeta -> getColumnName ( '_uid' ) ; $ this -> requiredFields [ 'leftnode' ] = $ sectionMeta -> getColumnName ( '_leftnode' ) ; $ this -> requiredFields [ 'rightnode' ] = $ sectionMeta -> getColumnName ( '_rightnode' ) ; $ this -> requiredFields [ 'level' ] = $ sectionMeta -> getColumnName ( '_level' ) ; $ this -> requiredFields [ 'created' ] = $ sectionMeta -> getColumnName ( '_created' ) ; $ this -> requiredFields [ 'modified' ] = $ sectionMeta -> getColumnName ( '_modified' ) ; $ this -> requiredFields [ 'site_uid' ] = $ sectionMeta -> getSingleAssociationJoinColumnName ( '_site' ) ; $ this -> requiredFields [ 'root_uid' ] = $ sectionMeta -> getSingleAssociationJoinColumnName ( '_root' ) ; $ this -> requiredFields [ 'parent_uid' ] = $ sectionMeta -> getSingleAssociationJoinColumnName ( '_parent' ) ; $ existingFields = array_keys ( $ schemaManager -> listTableColumns ( $ tableName ) ) ; $ missingFields = array_diff ( $ this -> requiredFields , $ existingFields ) ; if ( 0 < count ( $ missingFields ) ) { $ this -> output -> writeln ( "<error>Failed</error>" ) ; throw new BBException ( sprintf ( 'Following required fields are missing in table `%s`: `%s`.%s Cannot upgrade database storage anymore.' , $ tableName , implode ( '`, `' , $ missingFields ) , PHP_EOL ) ) ; } $ pageMeta = $ this -> em -> getClassMetadata ( 'BackBee\NestedNode\Page' ) ; $ tablePage = $ pageMeta -> getTableName ( ) ; $ sectionField = $ pageMeta -> getSingleAssociationJoinColumnName ( '_section' ) ; if ( ! in_array ( $ sectionField , $ existingFields ) ) { $ this -> em -> getConnection ( ) -> executeUpdate ( sprintf ( 'ALTER TABLE %s ADD COLUMN %s CHAR(32)' , $ tablePage , $ sectionField ) ) ; } $ positionField = $ pageMeta -> getColumnName ( '_position' ) ; if ( ! in_array ( $ positionField , $ existingFields ) ) { $ this -> em -> getConnection ( ) -> executeUpdate ( sprintf ( 'ALTER TABLE %s ADD COLUMN %s INT' , $ tablePage , $ positionField ) ) ; } $ this -> output -> writeln ( '<info>OK</info>' ) ; return $ this ; }
Checks for required fields in table `page`

@return \BackBee\Console\Command\UpgradeToPageSectionCommand
@throws BBException                                              Raises if table `page` doesn't exists or is incomplete
Checks for required fields in table page