A while ago i was tasked to program a Typo3 extension to write so called .conf files for the icinga2 montoring tool (has nothing to do with Typo3). Still let me explain some parts of it: Basically the backend user needs to create records of records of specific classes and set values for each records properties. Then i need to process the records to create these .conf files with the specific values with a php script.
I was tasked to use the scheduler in Typo3 for this. And here come the problems: How do i use this? I checked the documentation (https://docs.typo3.org/typo3cms/extensions/scheduler/Introduction/Index.html), but i still can't wrap my head around how to use it for my task. I can easily write an Action in a controller of a class to be executed in the frontend and in turn generate the con files... basically manually without the scheduler. But where do i put my php code to be run by the scheduler? I somehow seem not to understand the basical principle of the scheduler. Can i just run an Action of a specific controller of a class of my extension like i would in the Frontend via the scheduler?
I would suggest you use a command controller for this task.
The documentation shows how to create a command controller, which also may accept arguments.
Command controller tasks can directly be executed by TYPO3 scheduler (see screenshot below)
You may even configure task arguments for command controller tasks in TYPO3 scheduler.
I've created a deployment script for my Symfony applications that fetches updates from a git-repo. It downloads dependencies, updates schema, installs assets, then clears and warms up the cache
It works well (as far I know?) but I need a way to get/store the last time the cache was cleared. Preferably I don't want to write to a file or update a record in a database from the shell, I rather detect/fetch the the last time it was cleared and rebuilt inside my Symfony application.
Is there any way to do this? I thought of getting the created time of the prod cache folder..
Here's the script I wrote: https://github.com/StrikeForceZero/DeploySymfony/blob/master/DeploySymfony.sh
One way to do this would be to write to the Symfony logs using Symfony's built in logging service Monolog (http://symfony.com/doc/current/cookbook/logging/monolog.html). You can either create a Symfony console command (http://symfony.com/components/Console) that your script executes to write to the logs, or you can use inheritance to override one of the Symfony methods that you want to log, that simply calls the logger service, updates the log, and calls its parent method.
For example, instead of calling 'app/console cache:clear' you can call your child method that inherits from CacheClearCommand, update the configure method to set a new name for your command, override the execute method to call your log (either before or after the child executes its parent) and that should be about it. In your deployment script call your custom cache:clear command instead of Symfony's.
Today I bumped into something strange regarding an Artisan Command's lifecycle.
I added an artisan command named cronjobs:MyCommand.
Created the necessary files and classes.
Class MyCommand extends BaseCommand.
BaseCommand is something I put up to benchmark command line operations.
It consists of a constructor and destructor. The constructor keeps track of
the starting time of the operation, the destructor logs the current time minus
the starting time in a log table.
To my surprise I found out that the __destruct() function on my BaseCommand is
called 5 times in total every time I issue the cronjobs:MyCommand via artisan.
Is this normal behavior and if so how am I supposed to take care of logging instead?
Further testing with Symfony 2's command class showed that this is a problem native to Symfony 2, not so much with laravel 4.
Using a constructor/destructor in an artisan command's class (or its parent) in any useful way seems impossible at this point in time.
Any input is still highly appreciated!
Issue seems still not fixed.. I had also creaed a basecommand with __destruct method which is gettigng executed multiple times.
I created a shutdown method in my basecommand and calling at the end of mycommand.
I've got a symfony2 (php framework) app for which I've written a command that can be called from the command line. This command simply checks a table in the database for a task, then executes that task. What I need is a daemon-like creature that will enable this command to be run in the background whenever a row is inserted into this (mysql) database table. I can't do this with a cron job because the tasks required need to happen as quickly as possible, and will often need to happen in parallel.
Am I looking at this all wrong?
Server: Ubuntu 11.10
PHP: 5.3
Symfony: 2.1
mysql: 5.1.66
I would assume you are using some kind of a ORM for persistence. I would then probably use a hook like postInsert() in Propel
postInsert() code executed after insertion of a new object
or postPersist() in Doctrine.
postPersist - The postPersist event occurs for an entity after the entity has been made >persistent. It will be invoked after the database insert operations. Generated primary >key values are available in the postPersist event.
Here is some more information on lifecycle events.
Even if this is a very old question...
I've found https://github.com/mac-cain13/daemonizable-command
Probably useful for what you need to do.
I'm working on a project that has a fairly complex database (150+ tables). In order to be able to maintain changes, I've decided to add migrations, preferably using Yii or Laravel.
Does anybody know, if it is possible to generate a initial migration from an existing database?
Creating it by hand would:
take for ever and
be very error-prone.
If there is no way, does anybody know a good PHP-based framework, that supports such functionality?
Instructions for accomplishing this in Yii:
Add your database connection settings to protected/config/console.php.
Run yiic migrate create initial to create the stub code for the migration.
Copy contents of this gist to protected/commands/InitialDbMigrationCommand.php.
Run yiic initialdbmigration 'name_of_your_database' > initial_migration.php to generate up() and down() methods for initial database migration.
Copy and paste up() and down() methods from initial_migration.php to the file created in the protected/migrations folder in step 2.
'Doctrine Project' (aka Doctrine) has the ability to create DB migrations for existing DB structures, so you can recreate the existing structure. It can be easily implemented in Symfony, Laravel, also in Yii and many frameworks.
Sample from:
http://symfony.com/legacy/doc/doctrine/1_2/en/07-Migrations
From Database
If you have an existing database you can build a set of migration
classes that will re-create your database by running the following
command.
$ ./symfony doctrine:generate-migrations-db
From Models
If you have an existing set of models you can build a set of migration
classes that will create your database by running the following
command.
$ ./symfony doctrine:generate-migrations-models
Here is a Laravel package I created that does exactly that. It automatically generates clean and accurate Laravel migrations from your existing database.
As it doesn't make any assumptions of the database, it should work on any database structure while even keeping the original index and foreign key names.
https://github.com/Xethron/migrations-generator
Well since migration is about setting up your database structure and make changes to it, not to reflect a current database there is no such way.
And this is also not a step you have to make. You can start from where you are at the moment, which will make you able to rollback up to this point. Which means you can make migrations for your current tables without having to specify their entire structure, but just the changes only.
Let's say you have a table called user and want to add their firstname to it.
php artisan migrate:make add_firstname_to_user
Now go into application/migrations and find the migration file, add this
public function up()
{
Schema::table('user', function($table)
{
$table->string('firstname');
});
}
public function down() {
Schema::table('user', function($table)
{
$table->drop_column('firstname');
});
}
Now you can add migrate it
php artisan migrate:install // if you haven't run this, should only be once
php artisan migrate
.. and rollback using
php artisan migrate:rollback
This will add or drop the column firstname, without affecting your table in any other way.
As for Yii 1.x, schmunk has created a wonderful database-command yiic command.
This command covers only up migrations. You must write your own down migrations.
To use it:
Get the newest version from GitHub and put it's contents into /protected/commands folder (create one, if it does not exist). Note, that you need to put contents as is (without subfolder for this particular command), which is contrary to what we do for example for extensions.
Rename EDatabaseCommand.php file (and class inside) to DatabaseCommand.php, if you want to use yiic database command (as suggested in docs). Without this fix, you'll have to use yiic edatabase command, as there's slight inconsistency between docs and the code (at least in the newest version, as of writing this; maybe schmunk is going to fix this).
Having this, navigate back to protected folder in your console and execute yiic database dump migration_name --prefix=table_name.
This will create a migration protected/runtime/migration_name.php file with proper date and time in the beginning of file name, filled with series of CDbMigration commands to recreate your database schema. Visit "Usage" section in the docs to read more about customizing command.
I think that the answer is: https://github.com/jamband/yii2-schemadump for Yii2
"This command to generate the schema from an existing database."
I use both Yii and Laravel and I could not find what you require for either of them. They both create empty files and you need to create the migration script yourself.
For a table of 150 tables it will be challenge to create the migrations yourself, but it is not quite as hard as you imagine. Because you already have the information on the fields it should not take so long to create.
After doing some research, here's what you're going to need for Laravel: https://github.com/XCMer/larry-four-generator
(version 4 at least, who knows how long this will work, Laravel changes too fast and has too many breaking changes)
You'll want to run php artisan larry:fromdb and it'll show you the tables...You can also exclude or only process certain tables (look at the readme).
Again, super super useful if you like to build your schema in something like MySQL Workbench. I also saw mention of a package that would parse the workbench files...But the link was dead.
You may also wish to use this larry package with: https://github.com/JeffreyWay/Laravel-4-Generators
You can then create scaffolding a la CakePHP style.
Alternatively, try this package: https://github.com/barryvdh/laravel-migration-generator
There is one now for Yii:
This allows a distributed team to easily update the db locally and then distribute it's updates with thee other developers automatically with the rest of the code via a versioning control system (I used git). It also performs a full initial db dump to xml and to a migration file.
project home:
https://code.google.com/p/yii-automatically-generated-migration-files/
source code:
https://code.google.com/p/yii-automatically-generated-migration-files/source/checkout
I've created it from scratch as I was annoyed with the fact that I had to do this manually in order to distribute it to my team.
Hope it helps!
Feel free to share bugs, improvements and comments.