How to prevent silently discarding attributes in Laravel? - php

I'm very new to both PHP and to the barely-documented legacy codebase I'm debugging. One of the attributes on one of my models is being set to NULL on DB save, and I'm not clear why. This Q is mainly about my attempts to seal off one of the possibilities.
(It might be a type-conversion error - the model treats the field as an integer but the DB thinks it is a string, or that some code sets the field and other code doesn't, or that there are large sections of unreachable code and probably a few other possibilities too. Am tracing code, but it's a few dozen files of undocumented proprietary code, so please bear with me. It's tough to make a minimal reproducible example under the circumstances.)
I came across this article on configuring Eloquent strictness, and "silently discarding" this attribute sounded a lot like "set it to null without logging an exception", so I figured I'd try it. (The field of concern is listed in its particular model's protected $fillable attribute, so I might also be barking up the wrong tree...) As per the article, my (pre-existing, presumably working) app/Providers/AppServiceProvider.php now contains this import:
use Illuminate\Database\Eloquent\Model;
and it also contains the following function definition:
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
$this->trackDatabaseEvents();
Schema::defaultStringLength(191);
Model::preventSilentlyDiscardingAttributes(! $this->app->isProduction());
}
where I've only added the third line, and it's copied directly from the above how-to, and also appears in a couple other contexts... but when I try to compile the app, I get
#23 10.45 Generating optimized autoload files
#23 12.89 > Illuminate\Foundation\ComposerScripts::postAutoloadDump
#23 12.91 > #php artisan package:discover --ansi
#23 13.08 [2023-01-24 14:27:57] production.ERROR: SQLSTATE[08006] [7] could not translate host name "postgres" to address: Name or service not known (SQL: select * from "applications" limit 1)
#23 13.11 [2023-01-24 14:27:57] production.ERROR: [0] "Cannot instantiate abstract class Illuminate\Database\Eloquent\Model" on line 59 of file /app/app/Providers/AppServiceProvider.php
#23 13.11
#23 13.11 Error
#23 13.11
#23 13.11 Cannot instantiate abstract class Illuminate\Database\Eloquent\Model
#23 13.11
#23 13.11 at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2144
#23 13.12 2140▕ * #return mixed
#23 13.12 2141▕ */
#23 13.12 2142▕ public static function __callStatic($method, $parameters)
#23 13.12 2143▕ {
#23 13.12 ➜ 2144▕ return (new static)->$method(...$parameters);
#23 13.12 2145▕ }
#23 13.12 2146▕
#23 13.12 2147▕ /**
#23 13.12 2148▕ * Convert the model to its string representation.
#23 13.12
#23 13.12 1 app/Providers/AppServiceProvider.php:59
#23 13.12 Illuminate\Database\Eloquent\Model::__callStatic()
#23 13.12
#23 13.12 +7 vendor frames
#23 13.12 9 [internal]:0
#23 13.12 Illuminate\Foundation\Application::Illuminate\Foundation\{closure}()
#23 13.14 Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
I am using Postgres, and I can successfully compile the app if I copy out that one additional command in boot: Model::preventSilentlyDiscardingAttributes(! $this->app->isProduction());. Compilation in both cases is via Docker, and the crashing is at RUN composer install. Here's a trimmed version of the Dockerfile so folks can check version numbers, etc:
FROM ubuntu:focal as build
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y software-properties-common \
&& add-apt-repository -y ppa:ondrej/php \
&& apt-get install -y php8.1-fpm php8.1-cli php8.1-curl \
php8.1-mbstring php8.1-xml php8.1-pgsql php8.1-intl php8.1-zip php8.1-gd \
php8.1-gmagick php8.1-dev php-pear \
libpq-dev libevent-dev libssl-dev netcat unzip \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& printf "\n" | pecl install event
WORKDIR /app
< a bunch of COPY commands; trimmed for space >
RUN composer install
# --ignore-platform-reqs \
# --no-interaction \
# --no-plugins \
# --no-scripts \
# --prefer-dist
I don't know why those options are commented out, but might be able to find out. I included them here in case everyone assumes that I had one of them or some other option present. The options are the same - and commented out - both with and without the crash. The only change is the presence / absence of the Model::preventSilentlyDiscardingAttributes line in AppServiceProvider.php
Also, one of the comments asked about the docker-compose.yml. There is such a file, but I need to build the image before I can "compose" multiple images together. The other images referenced in the docker-compose are not running either when I have this line enabled or disabled.
Another of the comments got me looking into Composer Scripts and after skimming that page, I looked in my composer.json. That contains a scripts section:
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
},
I don't know if that's causing the problem, but "#php artisan package:discover --ansi" does appear at the end of the previously-quoted traceback.
To provide a bit more detail about the field "data_source" whose odd behavior started me down this path: The comment block just before the model class definition includes the line * #property mixed $data_source. Values assigned to the field in code always use constants defined on the class, and those constants are always integers. It is intended to act as a short enum type, there are three values (other than null): 1, 2, and 3. There is also a class-constant array which maps two of those three integers to strings, but use of that array during read & save is inconsistent, and grep for the map's name doesn't reveal anything that looks to me like automatic type-casting. If I view records from the DB in pgAdmin, it shows the column data type as "character varying (10)". All records in the DB have NULL values in that column. Some of the code that saves/updates records specifically set the column; some does not. So I'm adding log messages to try to figure out which pieces of code are actually involved.
Thank you for your attention and your help.

Related

Applying a patch to the Shopware 6 Core

My current version of Shopware has a small problem, for which I'd like to implement the following patch:
https://gitlab.com/mh2017/shopware6-patches/-/raw/master/core/variant-listing-updater.patch
To implement this patch I am using the cweagans/composer-patches plug-in. When running composer update the Shopware Core is attempted to be removed and re-installed:
Gathering patches for root package.
Removing package shopware/core so that it can be re-installed and re-patched.
- Removing shopware/core (6.4.7.0)
However the removal of the Core fails, as the update command fails:
> [ ! -f vendor/autoload.php ] || $PHP_BINARY bin/console system:update:prepare
ErrorException {#7
#message: "Warning: include(/var/www/html/vendor/composer/../shopware/core/Framework/Plugin/KernelPluginLoader/StaticKernelPluginLoader.php): failed to open stream: No such file or directory"
#code: 0
#file: "./vendor/symfony/error-handler/DebugClassLoader.php"
#line: 349
#severity: E_WARNING
trace: {
./vendor/symfony/error-handler/DebugClassLoader.php:349 { …}
./bin/console:49 {
›
› $pluginLoader = new StaticKernelPluginLoader($classLoader, null);
›
}
}
}
Script [ ! -f vendor/autoload.php ] || $PHP_BINARY bin/console system:update:prepare handling the pre-update-cmd event returned with error code 255
This seems to be due to the fact that the core isn't there when attempting to run this command. When attempting to run this with the --no-scripts command, the command does run but also does not patch the Shopware version (as it is also a script).
What would be the best way to apply patches to the Shopware core that also ensures that composer runs smoothly?
Write simple bash script like this and add it to composer script or run manually. I'm using this commands in my gitlab pipelines.
# apply commit
curl -o /tmp/NEXT-21468.patch https://github.com/shopware/platform/commit/285c5d4b6bf9f93f7ebfbbcb3354e95fb5adb6ee.patch
git apply -p3 --directory='vendor/shopware/core' < /tmp/NEXT-21468.patch
# use sed to replace case sensitive path
curl -o /tmp/NEXT-20216.patch https://github.com/shopware/platform/commit/bec6ac21a78ab84c7181dac2347e3e670f92033c.patch
sed -i 's|/src/Core/|/src/core/|g' /tmp/NEXT-20216.patch
sed -i 's|/src/Storefront/|/src/storefront/|g' /tmp/NEXT-20216.patch
git apply -p2 --directory='vendor/shopware' < /tmp/NEXT-20216.patch
# apply pull request
curl -o /tmp/NEXT-21994.patch https://patch-diff.githubusercontent.com/raw/shopware/platform/pull/2536.patch
git apply -p3 --directory='vendor/shopware/core' < /tmp/NEXT-21994.patch

Laravel queue job never ends only with timeout when I use queue:listen

I have an issue with the Laravel queue. It will start processing jobs, but then it hangs somewhere in the middle (based on custom echos to the log) and ends only with timeout. The problem is that the job should take no more than 1 min, but the job in the queue runs for more than 10 mins without any results nor any errors - except the standard timeout error.
The job
The job that should be processed in the queue is containing standard Eloquent selection and one update method that should update the other model's property.
// app\Listeners\CountReceivedTextAnswers
// There follows the listener's handle method. Nothing else is inside the
// Listener, it also implements ShouldQueue interface and InteractsWithQueue trait.
public function handle($event)
{
$questions = $this->question->whereTarget(['gl', 'povinn', 'ucit'], $event->evaluation->id, 'text');
$this->evaluation->updateOptions(
$event->evaluation->id,
'number_of_answers_to_text_questions',
$this->answer->countAnswersToManyQuestions($questions)
);
}
// app\Repositories\Answers\AnswersEloquentRepository
// This is the method that is called inside the listener. It passes
// collection of questions to the following method which should count
// answers on them.
public function countAnswersToManyQuestions(Collection $questions): int
{
$result = 0;
foreach ($questions as $question) {
$result += $this->countAnswersToQuestion($question);
}
return $result;
}
// This is the count method, it accepts Question model and count
// number of answers received on that question.
public function countAnswersToQuestion(Question $question): int
{
$select = [
'id',
'import_id',
'question_id',
'content',
'value',
'hidden',
'hidden_by',
'signed_by',
];
return Answer::select($select)
->whereDoesntHave('answered')
->where('question_id', '=', $question->id)
// Remove unwanted answers e.g. empty.
->when($question->form === 'text', function (Builder $query) {
$query->whereNotNull('content');
})
->when($question->form === 'slider', function (Builder $query) {
$query->whereNotNull('value');
})
->count();
}
// app\Repositories\Evaluation\EvaluationEloquentRepository
// This is the update method that is called to update the value
// inside the listener.
public function updateOptions($id, $field, $value)
{
$evaluation = $this->find($id);
$options = json_decode($evaluation->options, true);
$options[$field] = $value;
return $this->update($id, [
'options' => $options
]);
}
When I call the same method from listener manually in Tinker it takes around 30 sec to complete. Thus I guess the problem should not be related to the method itself, but something else, possibly configuration?
My setup
I'm using docker with five containers, two are based on my docker image (.dockerfile) which is based on the official php:7.3-fpm image with installed oci8 and few other extensions. The container's start script is based on this tutorial so I can use one container for both - the queue and the app. The rest of the containers are base on their official docker images - httpd:2.4-alpine, mysql:8.0 and redis:5-alpine. I should also note that I'm using Laravel 5.5
php.ini
These values I change in php.ini configuration. Rest should be default. It is set to be a quite generous, because at first I thought the error is related to php config, however is seems not, because there is no error in php's error log.
date.timezone=UTC
display_errors=on
log_errors=On
error_log=/var/www/storage/logs/php.log
opcache.enable=1
opcache.enable_cli=1
memory_limit = 512M
upload_max_filesize = 128M
post_max_size = 64M
max_execution_time=900
max_input_time=900
default_socket_timeout=60
starth.sh
#!/usr/bin/env bash
set -e
role=${CONTAINER_ROLE:-app}
env=${APP_ENV:-production}
if [[ "$env" != "local" ]]; then
echo "Caching configuration..."
(cd /var/www && php artisan config:cache && php artisan route:cache && php artisan view:cache)
fi
if [[ "$role" = "app" ]]; then
exec php-fpm
elif [[ "$role" = "queue" ]]; then
echo "Running the queue..."
php /var/www/artisan queue:listen --verbose --tries=10 --sleep=0 --timeout=800 --memory=512
elif [[ "$role" = "scheduler" ]]; then
while [[ true ]]
do
php /var/www/artisan schedule:run --verbose --no-interaction &
sleep 60
done
else
echo "Could not match the container role \"$role\""
exit 1
fi
The only error
There is the only error, that I'm able to find in laravel.log, however I don't think that the actual problem is in the length of the job as running it in Tinker takes far less time than the timeout is set to be.
[2019-05-22 16:06:39] local.ERROR: The process "'/usr/local/bin/php' 'artisan' queue:work 'redis' --once --queue='default' --delay=0 --memory=512 --sleep=0 --tries=10" exceeded the timeout of 800 seconds. {"exception":"[object] (Symfony\Component\Process\Exception\ProcessTimedOutException(code: 0): The process \"'/usr/local/bin/php' 'artisan' queue:work 'redis' --once --queue='default' --delay=0 --memory=512 --sleep=0 --tries=10\" exceeded the timeout of 800 seconds. at /var/www/vendor/symfony/process/Process.php:1335)
[stacktrace]
/var/www/vendor/symfony/process/Process.php(424): Symfony\Component\Process\Process->checkTimeout()
/var/www/vendor/symfony/process/Process.php(212): Symfony\Component\Process\Process->wait()
/var/www/vendor/laravel/framework/src/Illuminate/Queue/Listener.php(193): Symfony\Component\Process\Process->run(Object(Closure))
/var/www/vendor/laravel/framework/src/Illuminate/Queue/Listener.php(115): Illuminate\Queue\Listener->runProcess(Object(Symfony\Component\Process\Process), '512')
/var/www/vendor/laravel/framework/src/Illuminate/Queue/Console/ListenCommand.php(68): Illuminate\Queue\Listener->listen('redis', 'default', Object(Illuminate\Queue\ListenerOptions))
[internal function]: Illuminate\Queue\Console\ListenCommand->handle()
/var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
/var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
/var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
/var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(549): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
/var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array)
/var/www/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
/var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
/var/www/vendor/symfony/console/Application.php(960): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
/var/www/vendor/symfony/console/Application.php(255): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\ListenCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
/var/www/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
/var/www/vendor/laravel/framework/src/Illuminate/Console/Application.php(88): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
/var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
/var/www/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
{main}
"}
I have tried probably all possible advices that I've found on internet, I have changed all values in the php artisan queue:listen command and also in php.ini but it always ends with the same outcome. I have also tried to locate redis log, but without success, thus I moved the queue to the database and the result was always the same. Queue listener started the job, but then somehow hanged without any further information or error. I shuld also say that the worker with all these listeners and jobs works very well outside docker images.
I will be very grateful for any advice or tip! Also if you'd like to see more information, please let me know, I'll add them.
In the end I found that the queue worker was really exceeding the timeout. It was due to the fact that during some data migration were removed all foreign keys and indexes, thus loading relations from tables took too long. Redefining relationships in the DB made the queue worker significantly faster and error disappeared.
You could check your log, in storage/logs/laravel.log,
Maybe the error could be there

php artisan migrate fails due to laravel command

I have a laravel command that contains a user entity. I wrote a migration to modify the user table. When running php artisan migrate, I get an error because the user entity does not match the database (because this migration will make those changes).
I suspect that this means that the migrate command's process includes setting up laravel commands. Is there a way I can run php artisan migrate and the laravel command code not run?
I'm running laravel 5.1 and php 7.1.
Edit:
I didn't post any code, because it's not even getting to the migration. Here is the error message (the command was php artisan migrate).
This may be helpful was well. This is in the laravel command class that is causing the error. I can comment it out and the migration runs fine. That would be annoying to do for production though.
$userRepo = $repositoryFactory->getRepository(User::class);
$this->defaultUser = $userRepo->find(3000);
I just thought I should also include part of the stack trace that is in the laravel log file for this error.
#0 /project-path/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(176): Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))
#1 /project-path/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(150): Doctrine\DBAL\DBALException::wrapException(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'An exception oc...')
#2 /project-path/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(915): Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'SELECT t0.user_...', Array)
#3 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(712): Doctrine\DBAL\Connection->executeQuery('SELECT t0.user_...', Array, Array)
#4 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php(730): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->load(Array, NULL)
#5 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(462): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadById(Array)
#6 /project-path/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php(154): Doctrine\ORM\EntityManager->find('...', Array, NULL, NULL)
#7 /project-path/Emailer.php(53): Doctrine\ORM\EntityRepository->find(3000)
#8 /project-path/QuoteStaleEmailer.php(25): Emailer->__construct(...)
#9 [internal function]: QuoteStaleEmailer->__construct(...)
#10 /project-path/vendor/laravel/framework/src/Illuminate/Container/Container.php(780): ReflectionClass->newInstanceArgs(Array)
#11 /project-path/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('...', Array)
#12 /project-path/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('Servi...', Array)
According to Laravel 8 documentation , before renaming a column/table, ensure that you have installed the doctrine/dbal library via the Composer package manager.
Please run composer require doctrine/dbal to install
I came up with a decent work around. I don't know the correct terms to describe it, but looking at the stack trace, laravel sets up containers during a php artisan command. That includes containers for laravel command.
$this->defaultUser = $userRepo->find(3000) line was in the constructor, which meant it ran when the containers are setup. This causes an error because, the database for the user does not match the app setting for the user (because the migration hasn't run yet).
I moved the line to the getter function instead and set the default user there if it's empty, which isn't used when setting up the containers.
I tried installing laravel-websockets v2 and this error popped up when trying to migrate the tables. you need to install "doctrine/dbal" into your project and then run the migration
run composer require doctrine/dbal
run php artisan migrate

PHP artisan optimize returns error on bitBucket Pipeline

I'm trying to use bitBucket Pipeline with a Laravel. But everytime that run the pipeline return the follow error:
> post-install-cmd: Illuminate\Foundation\ComposerScripts::postInstall
> post-install-cmd: php artisan optimize --verbose
Generating optimized class loader
Compiling common classes
Script php artisan optimize --verbose handling the post-install-cmd event returned with an error
[RuntimeException]
Error Output:
Exception trace:
() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:196
Composer\EventDispatcher\EventDispatcher->doDispatch() at phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:94
Composer\EventDispatcher\EventDispatcher->dispatchScript() at phar:///usr/local/bin/composer/src/Composer/Installer.php:350
Composer\Installer->run() at phar:///usr/local/bin/composer/src/Composer/Command/InstallCommand.php:134
Composer\Command\InstallCommand->execute() at phar:///usr/local/bin/composer/vendor/symfony/console/Command/Command.php:256
Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:838
Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:189
Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:167
Composer\Console\Application->doRun() at phar:///usr/local/bin/composer/vendor/symfony/console/Application.php:120
Symfony\Component\Console\Application->run() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:98
Composer\Console\Application->run() at phar:///usr/local/bin/composer/bin/composer:43
require() at /usr/local/bin/composer:25
bitbucket-pipelines.yml:
# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: phpunit/phpunit:5.0.3
pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- composer install --verbose
The problem was solved, I needed to set some environments variable.
To be more specific, I use a collect errors' service called rollbar (really good by the way)
And in config/services.php it was setted like that:
'rollbar' => [
'access_token' => env('ROLLBAR_ACCESS_TOKEN'),
'level' => env('ROLLBAR_LEVEL', 'error'),
],
I just needed to set ROLLBAR_ACCESS_TOKEN variable in Settings/PIPELINES/Environment variables on BitBucket

Cache:clear fails with The annotation "#Doctrine\ORM\Mapping\HasLifeCycleCallbacks" ... does not exist

I'm trying to do a preview release for my customer.
Everything is working fine on my development host in the preview environment.
I created a tarball excluding the stuff that isn't needed on the live site.
tar \
--create \
--auto-compress \
--dereference \
--exclude=.DS_Store \
--exclude=.git \
--exclude=.idea \
--exclude=.nfs* \
--exclude=node_modules \
--exclude=tests \
--exclude=var/cache/* \
--exclude=ToDo* \
--exclude=var/logs/* \
--exclude=var/sessions/* \
--exclude=web/tickets/* \
--file ./preview.tgz
I transferred the tarball to the target host and unpacked it.
Then cded into the directory and issued
sudo bin/console cache:clear --env=preview
Symfony throws the following error:
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "#Doctrine\ORM\Mapping\HasLifeCycleCallbacks" in class Bcs\BcsVmsUserBundle\Entity\VmsUser does not exist, or could not be auto-loaded.
I have manually deleted the contents of the cache directory and still get this error.
2016-0801-1124: Additional information.
I re-generated the auto-load files on the target host. No change.
I verified that the the HasLifeCycleCallbacks class is defined in the autoload files. It's in autoload_static.php and in autoload_classmap.php.
I verified that the file specified in the auto-load files does, indeed, exist.
Verbose output from console cache:clear --env=preview
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "#Doctrine\ORM\Mapping\HasLifeCycleCallbacks" in class Bcs\BcsVmsUserBundle\Entity\VmsUser does not exist, or could not be auto-loaded.
Exception trace:
() at /var/www/wwui/preview/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54
Doctrine\Common\Annotations\AnnotationException::semanticalError() at /var/www/wwui/preview/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:708
Doctrine\Common\Annotations\DocParser->Annotation() at /var/www/wwui/preview/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:641
Doctrine\Common\Annotations\DocParser->Annotations() at /var/www/wwui/preview/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:334
Doctrine\Common\Annotations\DocParser->parse() at /var/www/wwui/preview/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php:195
Doctrine\Common\Annotations\AnnotationReader->getClassAnnotations() at /var/www/wwui/preview/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/CachedReader.php:83
Doctrine\Common\Annotations\CachedReader->getClassAnnotations() at /var/www/wwui/preview/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php:63
Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass() at /var/www/wwui/preview/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:102
Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass() at /var/www/wwui/preview/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:151
Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at /var/www/wwui/preview/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /var/www/wwui/preview/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78
Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() at /var/www/wwui/preview/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /var/www/wwui/preview/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:281
Doctrine\ORM\EntityManager->getClassMetadata() at /var/www/wwui/preview/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php:44
Doctrine\ORM\Repository\DefaultRepositoryFactory->getRepository() at /var/www/wwui/preview/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:698
Doctrine\ORM\EntityManager->getRepository() at /var/www/wwui/preview/var/cache/preview/appPreviewDebugProjectContainer.php:450
appPreviewDebugProjectContainer->getBcs_Vmsuser_RepositoryService() at /var/www/wwui/preview/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:275
Symfony\Component\DependencyInjection\Container->get() at /var/www/wwui/preview/var/cache/preview/appPreviewDebugProjectContainer.php:437
appPreviewDebugProjectContainer->getBcs_Vmsuser_LoaderService() at /var/www/wwui/preview/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:275
Symfony\Component\DependencyInjection\Container->get() at /var/www/wwui/preview/var/cache/preview/appPreviewDebugProjectContainer.php:411
appPreviewDebugProjectContainer->getBcs_Vmsuser_AuthenticatorService() at /var/www/wwui/preview/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:275
Symfony\Component\DependencyInjection\Container->get() at /var/www/wwui/preview/var/cache/preview/appPreviewDebugProjectContainer.php:4403
appPreviewDebugProjectContainer->getSecurity_Authentication_ManagerService() at /var/www/wwui/preview/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:275
Symfony\Component\DependencyInjection\Container->get() at /var/www/wwui/preview/var/cache/preview/appPreviewDebugProjectContainer.php:2476
appPreviewDebugProjectContainer->getSecurity_AuthorizationCheckerService() at /var/www/wwui/preview/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:275
Symfony\Component\DependencyInjection\Container->get() at /var/www/wwui/preview/var/cache/preview/appPreviewDebugProjectContainer.php:1103
appPreviewDebugProjectContainer->getDplhMenuUtilityService() at /var/www/wwui/preview/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:275
Symfony\Component\DependencyInjection\Container->get() at /var/www/wwui/preview/var/cache/preview/appPreviewDebugProjectContainer.php:1077
appPreviewDebugProjectContainer->getDplhMenuDebugCommandService() at /var/www/wwui/preview/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:275
Symfony\Component\DependencyInjection\Container->get() at /var/www/wwui/preview/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:123
Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() at /var/www/wwui/preview/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:98
Symfony\Bundle\FrameworkBundle\Console\Application->all() at /var/www/wwui/preview/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:72
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/wwui/preview/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117
Symfony\Component\Console\Application->run() at /var/www/wwui/preview/bin/console:29
Development host:
Ubuntu 14.04.4 LTS
PHP 7.0.7-4
Symfony 3.1.2
Target host:
Ubuntu 16.04.1 LTS
PHP 7.0.8-0
Symfony 3.1.2 (as part of the tarball)
Suggestions?
Turns out #Doctrine\ORM\Mapping\HasLifeCycleCallbacks should be #Doctrine\ORM\Mapping\HasLifecycleCallbacks (that's a lowercase c in cycle).
I develop on a Mac which has case-insensitive file systems, by default and deploy to Ubuntu.
Many thanks to sfix and trq on the #symfony IRC node for this answer.

Categories