sonata-project / SonataPageBundle

This bundle provides a Site and Page management through container and block services
https://docs.sonata-project.org/projects/SonataPageBundle
MIT License
218 stars 209 forks source link

site-install error: "Type error: trim() expects parameter 1 to be string, null given)" #965

Closed ob1201 closed 6 years ago

ob1201 commented 6 years ago

For a Symfony4 install

doctrine/cache                           v1.7.1             = v1.7.1             Caching library offering an object-oriented API for many cache backends
doctrine/doctrine-cache-bundle           1.3.2              = 1.3.2              Symfony Bundle for Doctrine Cache
doctrine/phpcr-bundle                    dev-master bb380a5 = dev-master bb380a5 Symfony DoctrinePHPCRBundle
doctrine/phpcr-odm                       1.4.4              = 1.4.4              Object-Document-Mapper for PHPCR
friendsofsymfony/http-cache              2.1.2              = 2.1.2              Tools to manage HTTP caching proxies with PHP
jackalope/jackalope                      1.3.5              = 1.3.5              Jackalope PHPCR library
phpcr/phpcr                              2.1.4              = 2.1.4              PHP Content Repository interfaces
phpcr/phpcr-utils                        1.4.0              = 1.4.0              PHP Content Repository implementation independant utilities
psr/cache                                1.0.1              = 1.0.1              Common interface for caching libraries
psr/simple-cache                         1.0.0              = 1.0.0              Common interfaces for simple caching
sonata-project/admin-bundle              3.31.1             = 3.31.1             The missing Symfony Admin Generator
sonata-project/block-bundle              3.12.0             = 3.12.0             Symfony SonataBlockBundle
sonata-project/cache                     1.1.1              ~ 2.0.1              Cache library
sonata-project/cache-bundle              2.x-dev c0de243    ~ dev-master 4010ae3 This bundle provides caching services
sonata-project/core-bundle               3.x-dev a71caca    ~ dev-master 885ce54 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.3.1              = 2.3.1              Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2              = 1.0.2              Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.4.2              = 3.4.2              Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.5.0              = 2.5.0              Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.8.0              = 1.8.0              Lightweight Exporter library
sonata-project/google-authenticator      2.0.0              = 2.0.0              Library to integrate Google Authenticator into a PHP project
sonata-project/media-bundle              3.10.2             = 3.10.2             Symfony SonataMediaBundle
sonata-project/notification-bundle       3.x-dev eecadfb    ~ dev-master 2f04b00 Symfony SonataNotificationBundle
sonata-project/page-bundle               dev-master 5c30634 = dev-master 5c30634 This bundle provides a Site and Page management through container and block services
sonata-project/seo-bundle                2.5.0              = 2.5.0              Symfony SonataSeoBundle
sonata-project/user-bundle               4.1.1              = 4.1.1              Symfony SonataUserBundle
symfony-cmf/core-bundle                  dev-master dfba976 = dev-master dfba976 Symfony CMF Core Bundle
symfony-cmf/menu-bundle                  dev-master 5c6bd22 = dev-master 5c6bd22 Symfony CMF Menu Bundle
symfony-cmf/resource                     1.0.0              = 1.0.0              Bundle which facilitates document resource location via Puli
symfony-cmf/resource-bundle              dev-master 331fb91 = dev-master 331fb91 Bundle which facilitates document resource location
symfony-cmf/resource-rest-bundle         dev-master 8f2ccc6 = dev-master 8f2ccc6 Bundle which provides a REST API for resources
symfony-cmf/routing                      dev-master e1bc515 = dev-master e1bc515 Extends the Symfony routing component for dynamic routes and chaining several routers
symfony-cmf/routing-bundle               dev-master bf20a1f = dev-master bf20a1f Symfony RoutingBundle
symfony-cmf/tree-browser-bundle          dev-master 14ddf7d = dev-master 14ddf7d Symfony CMF Tree Browser Bundle
symfony/cache                            v4.0.4             = v4.0.4             Symfony Cache component with PSR-6, PSR-16, and tags

create DBs

mysql>
  create database testdb;
  create database testdb_phpcr;

init

bin/console doctrine:phpcr:init:dbal --force
bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate --no-interaction

mysqlshow testdb
Database: testdb
+-----------------------+
|        Tables         |
+-----------------------+
| fos_user_group        |
| fos_user_user         |
| fos_user_user_group   |
| media__gallery        |
| media__gallery_media  |
| media__media          |
| migration_versions    |
| notification__message |
| page__block           |
| page__page            |
| page__site            |
| page__snapshot        |
+-----------------------+

mysqlshow testdb_phpcr
Database: testdb_phpcr
+----------------------------+
|           Tables           |
+----------------------------+
| phpcr_binarydata           |
| phpcr_internal_index_types |
| phpcr_namespaces           |
| phpcr_nodes                |
| phpcr_nodes_references     |
| phpcr_nodes_weakreferences |
| phpcr_type_childs          |
| phpcr_type_nodes           |
| phpcr_type_props           |
| phpcr_workspaces           |
+----------------------------+

create admin user

bin/console fos:user:create <user> <email> <password> --super-admin

create site

bin/console sonata:page:create-site \
 --name='test' \
 --host='test.local' \
 --relativePath=/ \
 --enabled=true \
 --enabledFrom=- --enabledTo=- \
 --default=true \
 --locale='en'

    ...
    Site created !

    You can now create the related pages and snapshots by running the followings commands:
      php app/console sonata:page:update-core-routes --site=1
      php app/console sonata:page:create-snapshots --site=1

next step FAILs

bin/console sonata:page:update-core-routes --site=all

    ================================================
     > Updating core routes for site : test - //test.local

    ================================================
    In Page.php line 311:
      Type error: trim() expects parameter 1 to be string, null given

in dev.log

php.INFO: User Deprecated: The Knp\Bundle\MenuBundle\EventListener\VoterInitializerListener class is deprecated since 2.2 and will be removed in 3.0. {"exception":"[object] (ErrorException(code: 0): User Deprecated: The Knp\\Bundle\\MenuBundle\\EventListener\\VoterInitializerListener class is deprecated since 2.2 and will be removed in 3.0. at /opt/evals/symfony4/vendor/knplabs/knp-menu-bundle/src/EventListener/VoterInitializerListener.php:5)"} []
php.INFO: User Deprecated: The Sonata\CacheBundle\Invalidation\SimpleCacheInvalidation class is deprecated since version 2.4 and will be removed in 3.0. Use Sonata\Cache\Invalidation\SimpleCacheInvalidation instead. {"exception":"[object] (ErrorException(code: 0): User Deprecated: The Sonata\\CacheBundle\\Invalidation\\SimpleCacheInvalidation class is deprecated since version 2.4 and will be removed in 3.0. Use Sonata\\Cache\\Invalidation\\SimpleCacheInvalidation instead. at /opt/evals/symfony4/vendor/sonata-project/cache-bundle/src/Invalidation/SimpleCacheInvalidation.php:17)"} []
doctrine.DEBUG: SELECT t0.enabled AS enabled_1, t0.name AS name_2, t0.relative_path AS relative_path_3, t0.host AS host_4, t0.enabled_from AS enabled_from_5, t0.enabled_to AS enabled_to_6, t0.is_default AS is_default_7, t0.created_at AS created_at_8, t0.updated_at AS updated_at_9, t0.locale AS locale_10, t0.title AS title_11, t0.meta_keywords AS meta_keywords_12, t0.meta_description AS meta_description_13, t0.id AS id_14 FROM page__site t0 [] []
doctrine.DEBUG: SELECT t0.route_name AS route_name_1, t0.page_alias AS page_alias_2, t0.type AS type_3, t0.position AS position_4, t0.enabled AS enabled_5, t0.decorate AS decorate_6, t0.edited AS edited_7, t0.name AS name_8, t0.slug AS slug_9, t0.url AS url_10, t0.custom_url AS custom_url_11, t0.request_method AS request_method_12, t0.title AS title_13, t0.meta_keyword AS meta_keyword_14, t0.meta_description AS meta_description_15, t0.javascript AS javascript_16, t0.stylesheet AS stylesheet_17, t0.raw_headers AS raw_headers_18, t0.template AS template_19, t0.created_at AS created_at_20, t0.updated_at AS updated_at_21, t0.id AS id_22, t0.site_id AS site_id_23, t0.parent_id AS parent_id_24, t0.target_id AS target_id_25 FROM page__page t0 WHERE t0.url = ? AND t0.site_id = ? LIMIT 1 ["/",1] []
php.INFO: User Deprecated: The "Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait::render()" method is considered final since version 3.4. It may change without further notice as of its next major version. You should not extend it from "Sonata\MediaBundle\Controller\MediaAdminController". {"exception":"[object] (ErrorException(code: 0): User Deprecated: The \"Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait::render()\" method is considered final since version 3.4. It may change without further notice as of its next major version. You should not extend it from \"Sonata\\MediaBundle\\Controller\\MediaAdminController\". at /opt/evals/symfony4/vendor/symfony/debug/DebugClassLoader.php:256)"} []
php.INFO: User Deprecated: The "Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait::render()" method is considered final since version 3.4. It may change without further notice as of its next major version. You should not extend it from "Sonata\MediaBundle\Controller\GalleryAdminController". {"exception":"[object] (ErrorException(code: 0): User Deprecated: The \"Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait::render()\" method is considered final since version 3.4. It may change without further notice as of its next major version. You should not extend it from \"Sonata\\MediaBundle\\Controller\\GalleryAdminController\". at /opt/evals/symfony4/vendor/symfony/debug/DebugClassLoader.php:256)"} []
doctrine.DEBUG: SELECT t0.route_name AS route_name_1, t0.page_alias AS page_alias_2, t0.type AS type_3, t0.position AS position_4, t0.enabled AS enabled_5, t0.decorate AS decorate_6, t0.edited AS edited_7, t0.name AS name_8, t0.slug AS slug_9, t0.url AS url_10, t0.custom_url AS custom_url_11, t0.request_method AS request_method_12, t0.title AS title_13, t0.meta_keyword AS meta_keyword_14, t0.meta_description AS meta_description_15, t0.javascript AS javascript_16, t0.stylesheet AS stylesheet_17, t0.raw_headers AS raw_headers_18, t0.template AS template_19, t0.created_at AS created_at_20, t0.updated_at AS updated_at_21, t0.id AS id_22, t0.site_id AS site_id_23, t0.parent_id AS parent_id_24, t0.target_id AS target_id_25 FROM page__page t0 WHERE t0.route_name = ? AND t0.site_id = ? LIMIT 1 ["fos_js_routing_js",1] []
console.ERROR: Error thrown while running command "sonata:page:update-core-routes --site=all". Message: "trim() expects parameter 1 to be string, null given" {"error":"[object] (TypeError(code: 0): trim() expects parameter 1 to be string, null given at /opt/evals/symfony4/vendor/sonata-project/page-bundle/src/Model/Page.php:311)","command":"sonata:page:update-core-routes --site=all","message":"trim() expects parameter 1 to be string, null given"} []
console.DEBUG: Command "sonata:page:update-core-routes --site=all" exited with code "1" {"command":"sonata:page:update-core-routes --site=all","code":1} []
php.CRITICAL: Type error: trim() expects parameter 1 to be string, null given {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Type error: trim() expects parameter 1 to be string, null given at /opt/evals/symfony4/vendor/sonata-project/page-bundle/src/Model/Page.php:311)"} []

this trim error appears in a number of online references here's one

Fatal error: Uncaught TypeError: trim() expects parameter 1 to be string, null given #6 https://github.com/yireo/Yireo_CheckoutTester2/issues/6

code change is a condition string wrapper around trim https://github.com/yireo/Yireo_CheckoutTester2/pull/7/files#diff-735f70c1f948ebbd90915b1548d93432

Helper/Data.php
    @@ -49,7 +49,7 @@ public function enabled() : bool
          */
         public function hasAccess() : bool
         {
    -        $ip = $this->getConfigValue('ip');
    +        $ip = (string)$this->getConfigValue('ip');
             $ip = trim($ip);

             $realIp = $this->getIpAddress();
greg0ire commented 6 years ago

Can you make a pull request based on your code change?

ob1201 commented 6 years ago

thx