Notice: Undefined property: DOMDocument::$documentElement - symfony

I recently re-opened an old (1 year) Symfony project and I am having an error on every page (I don't remember having this issue a year ago) :
[exception] 500 | Internal Server Error | Symfony\Component\Config\Exception\FileLoaderLoadException
/var/www/[...]/wdt.xml
ContextErrorException: Notice: Undefined property: DOMDocument::$documentElement
If I clear the cache, the error disappear but as soon as I edit and save a file, the error is showing up again.
The project was using Symfony 2.8 and I updated to Symfony 3.2 but it didn't solve the issue.
I don't think the problem is related to the wdt.xml file and I think it might be related to my laptop config.
I don't really know where to start to investigate so any suggestion is welcome!
Edit 1 :
I am actually having the same problem with another project I created few days ago. The project don't use any additional bundles and I just created 5 entities and generated the MySQL database.
Edit 2 :
After some more researched, I decided to create a new Ubuntu VM and test a new Symfony project and it just work perfectly so it must be something to do with the configuration on my laptop.
Edit 3 :
After some more tests, here is what I get when I add a print_r($dom); in the file XmlUtils.php (vendor/symfony/symfony/src/Symfony/Component/Config/Util/XmlUtils.php) line 59 :
Ubuntu VM (no error) :
DOMDocument Object ( [doctype] => [implementation] => (object value omitted) [documentElement] => (object value omitted) [actualEncoding] => [encoding] => [xmlEncoding] => [standalone] => 1 [xmlStandalone] => 1 [version] => 1.0 [xmlVersion] => 1.0 [strictErrorChecking] => 1 [documentURI] => /var/www/my_project/web/ [config] => [formatOutput] => [validateOnParse] => 1 [resolveExternals] => [preserveWhiteSpace] => 1 [recover] => [substituteEntities] => [nodeName] => #document [nodeValue] => [nodeType] => 9 [parentNode] => [childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => [attributes] => [ownerDocument] => [namespaceURI] => [prefix] => [localName] => [baseURI] => /var/www/my_project/web/ [textContent] => %kernel.charset% %kernel.default_locale% )
Ubuntu laptop (error) :
DOMDocument Object ( [validateOnParse] => 1 [nodeName] => #document [nodeValue] => [nodeType] => 9 [parentNode] => [childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => [attributes] => [ownerDocument] => [namespaceURI] => [prefix] => [localName] => [baseURI] => /var/www/lab/symfony/booklib/web/ [textContent] => %kernel.charset% %kernel.default_locale% )
It looks like there is some missing information on my laptop...
So basically, the function $dom->loadXML doesn't return the same value on my laptop environment and inside the VM... any idea why?

I have Ubuntu 16.04 installation with php7.0.15, and i fixed the error by just removing php-xdebug extension.
sudo apt-get purge php-xdebug

I finally resolved the problem by uninstalling / reinstalling php7.
I have no idea why I had this issue though...

In my case the error was triggered by the dom.so extension being loaded in two places. Removing one fixed the problem.

This might be relevant:
https://getcomposer.org/doc/articles/troubleshooting.md#xdebug-impact-on-composer
TLDR: Use COMPOSER_ALLOW_XDEBUG=1 if you are using xdebug with composer.

This is very strange BUT try to change php extensions load order in php config. This solve my problem... move dom extension above or below in list

In my case the dom extension was enabled twice. Once in the dom.ini and also in the php.ini. I removed the extension=dom.so entry from the php.ini and reloaded the apache2 webserver.

Hi I also meet this problem. The way I resolve it is:
composer update
Hope that help some one.

Thank #pjehan. I had the same problem and I've lost a day. Finally, I did like you and it was successful.
Just specify one thing: unistall PHP 7.0.x and PHP 7.1.3 intaller (stable version for PHP 7). The link of the version PHP 7 stable: http://php.net/downloads.php
Thank you so much, #pjehan, you saved my life :D

I solved the problem by disabling xdebug for the cli

Related

Can I set the cardinality of an entity_reference to a config entity?

I programmatically created an entity_reference (to a config entity) field via hook_entity_base_field_info (see code below).
All works fine until I try to define its cardinality. As soon as I add this, I get fatal error because Drupal can't find the database table user__foo.
$fields['foo'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Foo field'))
->setDescription(t('Foo bar field'))
->setSetting('target_type', 'my_config_entity')
->setSetting('handler', 'default')
// ->setCardinality(\Drupal\Core\Field\FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'entity_reference_label',
'weight' => 6,
])
->setDisplayOptions('form', [
'type' => 'options_buttons',
'weight' => 7,
]);
FYI, when doing a clean install with the cardinality uncommented, all works fine, so it's probably a matter of writing an update hook for existing sites to install storage for this new field (something done by drush entity-update earlier).

COMMERCE ORDER - PDOException: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction

Here is my error message
PDOException: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when
trying to get lock; try restarting transaction:
UPDATE {commerce_order} SET
order_number=:db_update_placeholder_0, revision_id=:db_update_placeholder_1,
type=:db_update_placeholder_2, uid=:db_update_placeholder_3,
mail=:db_update_placeholder_4, status=:db_update_placeholder_5,
created=:db_update_placeholder_6, changed=:db_update_placeholder_7,
placed=:db_update_placeholder_8, hostname=:db_update_placeholder_9,
data=:db_update_placeholder_10 WHERE (order_id = :db_condition_placeholder_0) ;
Array ( [:db_update_placeholder_0] => 201805822 [:db_update_placeholder_1] => 16807
[:db_update_placeholder_2] => commerce_order [:db_update_placeholder_3] => 0
[:db_update_placeholder_4] => [:db_update_placeholder_5] => checkout_checkout
[:db_update_placeholder_6] => 1540480400 [:db_update_placeholder_7] =>
1540481979 [:db_update_placeholder_8] => 0 [:db_update_placeholder_9] =>
128.199.161.50 [:db_update_placeholder_10] => a:4:
{s:17:"last_cart_refresh";i:1540481976;s:16:"shipping_service";s:17:"shipping_custom|1";s:14:"with_backorder";s:0:"";s:17:"backorder_service";s:5:"_none";}
[:db_condition_placeholder_0] => 5056 ) in drupal_write_record() (line 7387 of ~/public_html/includes/common.inc).
anyone can help me? whats wrong with that things?
The best fix is changing your transaction isolation level (to READ COMMITTED).
Try adding this to your settings.php. It's a common problem in high read/write Drupal sites with many fields.
$databases['default']['default']['init_commands'] = array(
'isolation' => "SET SESSION tx_isolation='READ-COMMITTED'"
);

Corrupt Drupal menu

Running Drupal 7.26 with nothing fancy and have started to encounter a corruption issue with the menu system. We started seeing the following error (truncated to fit). Doing a drush or a manual clear cache doesn't fix it, setting menu_router.weight to NULL yes, truncating both the menu_links and menu_router tables still produces the error. Links oddly menu still appear on the site, but only some not all.
I suspect that the issue might be caused by a page view (using views3) with a set path, but I can't see why that would be as it is again just a normal path.
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column
'weight' at row 9: INSERT INTO {menu_router} (path, load_functions, to_arg_functions,
access_callback, access_arguments, page_callback, page_arguments, delivery_callback, fit,
number_parts, context, tab_parent, tab_root, title, title_callback, title_arguments,
theme_callback, theme_arguments, type, description, position, weight, include_file) VALUES
.... (truncated) ....
(:db_insert_placeholder_184, :db_insert_placeholder_185, :db_insert_placeholder_186,
:db_insert_placeholder_187, :db_insert_placeholder_188, :db_insert_placeholder_189,
:db_insert_placeholder_190, :db_insert_placeholder_191, :db_insert_placeholder_192,
:db_insert_placeholder_193, :db_insert_placeholder_194, :db_insert_placeholder_195,
:db_insert_placeholder_196, :db_insert_placeholder_197,); Array (
.... (truncated) ....
[:db_insert_placeholder_180] => Ajax callback for view loading.
[:db_insert_placeholder_181] => [:db_insert_placeholder_182] => 0
[:db_insert_placeholder_183] => sites/all/modules/contrib/views/includes/ajax.inc
[:db_insert_placeholder_184] => volunteering/opportunities [:db_insert_placeholder_185] =>
[:db_insert_placeholder_186] => [:db_insert_placeholder_187] => ctools_access_menu
[:db_insert_placeholder_188] => a:1:{i:0;a:2:{s:4:"type";s:4:"none";s:8:"settings";N;}}
[:db_insert_placeholder_189] => page_manager_page_execute [:db_insert_placeholder_190] =>
a:1:{i:0;s:13:"volunteering_";} [:db_insert_placeholder_191] =>
[:db_insert_placeholder_192] => 3 [:db_insert_placeholder_193] => 2
[:db_insert_placeholder_194] => 0 [:db_insert_placeholder_195] =>
[:db_insert_placeholder_196] => volunteering/opportunities [:db_insert_placeholder_197] =>
Volunteering opportunities [:db_insert_placeholder_198] => t [:db_insert_placeholder_199]
=> [:db_insert_placeholder_200] => [:db_insert_placeholder_201] => a:0:{} ) in
_menu_router_save() (line 3837 of /var/mysite/dev/includes/menu.inc).
For some strange reason the function page_manager_list_page() in ctools page manager > page_manager.admin.inc wasn't setting a numeric weight. Not sure how or why it isn't checking it is not a an integer, but it doesn't which caused the issue.

laravel development environment sqlite database does not exist

Trying to use sqlite in development environment. It seems to detect the environment correctly but when I try to migrate to development.sqlite I get exception thrown "database does not exist"
artisan command
php artisan migrate --env=development
bootstrap/start.php
$env = $app->detectEnvironment(array(
'development' => array('localhost'),
));
app/config/development/database.php
<?php
return array(
'default' => 'sqlite',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/development.sqlite',
'prefix' => '',
)
)
);
As far as I know laravel is supposed to create the file if it does not exist but since it didn't I tried manually creating the file and still get the exception thrown.
UPDATE: Maybe something not right with the env because the same thing happens if I try ':memory' for the database.
UPDATE 2: I tried running the sample unit test but add to TestCase.php
/**
* Default preparation for each test
*
*/
public function setUp()
{
parent::setUp(); // Don't forget this!
$this->prepareForTests();
}
/**
* Creates the application.
*
* #return Symfony\Component\HttpKernel\HttpKernelInterface
*/
public function createApplication()
{
$unitTesting = true;
$testEnvironment = 'testing';
return require __DIR__.'/../../bootstrap/start.php';
}
/**
* Migrates the database and set the mailer to 'pretend'.
* This will cause the tests to run quickly.
*
*/
private function prepareForTests()
{
Artisan::call('migrate');
Mail::pretend(true);
}
And this too gives the same exception though the testing env is already shipped with laravel. So I'll see if I can find any new issues on that.
Wow, typos and wrong paths.
Copying the sqlite array from config/database.php into config/development/database.php I forgot to change the path to the development.sqlite file from
__DIR__.'/../database/development.sqlite'
to
__DIR__.'/../../database/development.sqlite'
And for the in memory test it should have been
':memory:'
instead of
':memory'
I noticed that my database.php file had the following
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
I changed it to read the following, and it worked just fine.
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
One of the problem which I faced was I use "touch storage/database.sqlite" in terminal, so database is created in Storage folder instead of database folder.
in my config/database.php path is database_path('database.sqlite')
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
than I use command "php artisan migrate" which gave me error "Database (/Applications/MAMP/htdocs/FOLDER_NAME/database/database.sqlite) does
not exist."
so it's obvious database file is not in database folder as It was generated in Storage folder, so copy "database.sqlite" from storage folder or run command "touch database/database.sqlite"
Hope that helps.!!
Well, my answer is kinda outdated, but anyway. I faced the same problem, but with Laravel 5, I am using Windows 7 x64. First I manually created SQLite database called 'db' and placed it into storage directory, then fixed my .env file like this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=oBxQMkpqbENPb07bLccw6Xv7opAiG3Jp
DB_HOST=localhost
DB_DATABASE='db'
DB_USERNAME=''
DB_PASSWORD=''
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null`
I thought it would fix my problems, but the command line keeps telling me that database doesn't exist. And then I just checked the path to db in my database.php file and this is why I put database file into storage directory. But nothing changed. And finally I checked db's extension and it was .db, not .sqlite as default extension you see in your sqlite block in database.php. So this is how I reconfigured sqlite piece:
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path().'/db.db',
'prefix' => '',
],
And of course don't forget to set sqlite as default database in your database.php file. Good luck!
For me it was that path to database had to be '/var/www/html' + location to the database in your project. In my case database was stored in database/db.sqlite so DB_DATABASE='/var/www/html/database/db.sqlite'
I had the same error while running a GitHub action test workflow.
For me the solution was to define the relative path to the database archive into the workflow file:
on:
...
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
jobs:
laravel-tests:
...
I think that the previous answers reduce the importance of the config and most likely the developers wanted to get the database file like this:
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => database_path(env('DB_DATABASE', 'database').'.sqlite'), // <- like this
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
Tested on Laravel 9.x

zend framework 2 notice appears in console when call a console action

I have follow the simple steps of zend documentation to develop a many simple console action.
My action have only one literal param. It works ok and the action is executed but before, in each call appears following notice and a stack trace.
How I do for remove / solve this message
Notice: Undefined index: HTTP_ACCEPT_LANGUAGE in C:\xampp\htdocs\pfc_desarrollo\module\SecureDraw\Module.php on line 124
Call Stack:
0.0003 121464 1. {main}() C:\xampp\htdocs\pfc_desarrollo\public\index.php:0
0.0079 237776 2. Zend\Mvc\Application::init() C:\xampp\htdocs\pfc_desarrollo\public\index.php:12
0.1589 1822568 3. Zend\Mvc\Application->bootstrap() C:\xampp\htdocs\pfc_desarrollo\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php:239
0.2135 2232464 4. Zend\EventManager\EventManager->trigger() C:\xampp\htdocs\pfc_desarrollo\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php:142
0.2135 2232584 5. Zend\EventManager\EventManager->triggerListeners() C:\xampp\htdocs\pfc_desarrollo\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php:204
0.2350 2387304 6. call_user_func() C:\xampp\htdocs\pfc_desarrollo\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php:460
0.2350 2387320 7. SecureDraw\Module->onBootstrap() C:\xampp\htdocs\pfc_desarrollo\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php:460
--------------------------------HELLOOOOOO------------------
This is my action / route definition
//module.php
'console' => array(
'router' => array(
'routes' => array(
'hello' => array(
'options' => array(
'route' => 'hello',
'defaults' => array(
'controller' => 'SecureDraw\Controller\Participant',
'action' => 'hello',
),
),
), //Line 124
),
),
),
//Participant.php
public function helloAction(){
return "--------------------------------HELLOOOOOO------------------";
}
You must be trying to access the Server Variable HTTP_ACCEPT_LANGUAGE inside your Module.php file.
$_SERVER['HTTP_ACCEPT_LANGUAGE'] is usally set using the Browser which has requested the page, but as your are running the app from the console it is probably not getting set.
You should check to see if it's set before accessing it.

Resources