Download the PHP package timokoerber/laravel-one-time-operations without Composer

On this page you can find all versions of the php package timokoerber/laravel-one-time-operations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-one-time-operations

One-Time Operations for Laravel

One-Time Operations for Laravel

Run operations once after deployment - just like you do it with migrations!


Take your CI/CD to the next Level with One-Time Operations for Laravel! 🚀

Create specific classes for a one-time usage, that can be executed automatically after each deployment. Same as migrations they get processed once and then never again. Perfect for seeding or updating some data instantly after some database changes or feature updates.

This package is for you if...

Installation

Require this package with composer:

Create the required table in your database:

Now you're all set!

Commands

Create operation files

Create new operation file:

Create file without any attributes:

Process operations

Process all new operation files:

Force synchronous execution:

Force asynchronous execution:

Test mode (don't flag operations as processed):

Run command isolated:

Force a specific queue for the job:

Only process operations with a specific tag:

Re-run one specific operation:

Show operations

Show all operations:

Show pending operations:

Show processed operations:

Show disposed operations:

Use multiple filters to show operations:

Tutorials

CI/CD & Deployment-Process

The One-Time Operations work exactly like Laravel Migrations. Just process the operations after your code was deployed and the migrations were migrated. You can make it part of your deployment script like this:

Edit config

By default, the following elements will be created in your project:

If you want to use a different settings just publish and edit the config file:

This will create the file config/one-time-operations.php with the following content.

Make changes as you like.

Create One-Time Operation files

One-Time Operations for Laravel - Create One-Time Operation files

One-Time Operations for Laravel - Create One-Time Operation files

To create a new operation file execute the following command:

This will create a file like operations/XXXX_XX_XX_XXXXXX_awesome_operation.php with the following content.

Provide your code in the process() method, for example:

By default, the operation is being processed asynchronously (based on your configuration) by dispatching the job OneTimeOperationProcessJob. By default, the operation is being dispatched to the default queue of your project. Change the $queue as you wish.

You can also execute the code synchronously by setting the $async flag to false. (this is only recommended for small operations, since the processing of these operations should be part of the deployment process)

Hint: If you use synchronous processing, the $queue attribute will be ignored (duh!).

Create a cleaner operation file

If you don't need all the available attributes for your operation, you can create a cleaner operation file with the --essential or -e option:

Custom operation file

You can provide a custom class layout in /stubs/one-time-operation.stub, which will be used to create a new operation file.

Processing the operations

One-Time Operations for Laravel - Processing the operations

Use the following call to process all new operation files.

Your code will be executed, and you will find all the processed operations in the operations table:

id name dispatched processed_at
1 XXXX_XX_XX_XXXXXX_awesome_operation async 2015-10-21 07:28:00

After that, this operation will not be processed anymore.

Dispatching Jobs synchronously or asynchronously

For each operation a OneTimeOperationProcessJob is being dispatched, either with dispatch() oder dispatchSync() based on the $async attribute in the operation file.

By providing the --sync or --async option with the operations:process command, you can force a synchronously/asynchronously execution and ignore the attribute:

Hint! If operation:process is part of your deployment process, it is not recommended to process the operations synchronously, since an error in your operation could make your whole deployment fail.

Force different queue for all operations

You can provide the --queue option in the artisan call. The given queue will be used for all operations, ignoring the $queue attribute in the class.

Run commands isolated on Multi-Server Architecture

If you work with a Multi-Server Architecture you can use --isolated option to make sure to only run one instance of the command (Laravel Isolatable Commands).

Run only operations with a given tag

You can provide the $tag attribute in your operation file:

That way you can filter operations with this specific tag when processing the operations:

This is quite usefull if, for example, you want to process some of your operations before and some after the migrations:

You can also provide multiple tags:

Hint! operations:process (without tags) still processes all operations, even if they have a tag.

Re-run an operation

One-Time Operations for Laravel - Re-run an operation manually

If something went wrong (or if you just feel like it), you can process an operation again by providing the name of the operation as parameter in operations:process.

Testing the operation

You might want to test your code a couple of times before flagging the operation as "processed". Provide the --test flag to run the command again and again.

Showing all operations

One-Time Operations for Laravel - Showing all operations

So you don't have to check the database or the directory for the existing operations, you can show a list with operations:show. Filter the list with the available filters pending, processed and disposed.

Deleting operations

The whole idea of this package is, that you can dispose the operations once they were executed, so your project won't be cluttered with files and code, you won't be using anymore.

So you just need to delete the files from your repository

The deleted operations will be shown as DISPOSED when you call operations:show, so you still have a history on all the processed operations.

Testing

License

Copyright © Timo Körber | www.timokoerber.com

"One-Time Operations for Laravel" is open-sourced software licensed under the MIT license.


All versions of laravel-one-time-operations with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/contracts Version ^9.0|^10.0|^11.0
illuminate/support Version ^9.0|^10.0|^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package timokoerber/laravel-one-time-operations contains the following files

Loading the files please wait ....