Giter VIP home page Giter VIP logo

cronexpressionbundle's Introduction

Cron Expression Bundle

Latest Version Latest Unstable Version Software License Build Status Code Coverage

Symfony bundle that integrates dragonmantank/cron-expression

Installation

Step 1: Download

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require setono/cron-expression-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the bundle

If you use Symfony Flex it will be enabled automatically. Else you need to add it to the bundles.php.

<?php
// config/bundles.php

return [
    // ...
    Setono\CronExpressionBundle\SetonoCronExpressionBundle::class => ['all' => true],
    // ...
];

Usage

Add to form type

<?php
// src/Form/TaskType.php

namespace App\Form;

use Setono\CronExpressionBundle\Form\Type\CronExpressionType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;

class TaskType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('task')
            ->add('schedule', CronExpressionType::class)
            ->add('save', SubmitType::class)
        ;
    }
}

Add to entity

<?php

declare(strict_types=1);

namespace App\Entity;

use Cron\CronExpression;
use Doctrine\ORM\Mapping as ORM;
use Setono\CronExpressionBundle\Doctrine\DBAL\Types\CronExpressionType;

#[ORM\Entity]
class Task
{
    #[ORM\Column(type: CronExpressionType::CRON_EXPRESSION_TYPE)]
    private CronExpression $schedule;
}

cronexpressionbundle's People

Contributors

benmorel avatar chris53897 avatar hanmac avatar loevgaard avatar or-benjamin avatar simonsolutions avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cronexpressionbundle's Issues

Brick ReflectionTools can't be updated because dropped getPropertyTypes

newer brick ReflectionTools dropped getPropertyTypes currently used by this Bundle

without this, does this bundle even need Brick Reflection anymore?

my main problem is that brick reflection still uses an older version of doctrine/annotations that prevents my other modules from updating

Nullable value for doctrine type is not supported

Hi, i am using following field definition for my entity:

public ?CronExpression $schedule;
<field name="schedule" type="cron_expression" nullable="true" />

It is not possible to persist with null value as i get following error:

Cron\CronExpression::factory(): Argument #1 ($expression) must be of type string, null given, called in /var/www/vendor/setono/cron-expression-bundle/src/Doctrine/DBAL/Types/CronExpressionType.php on line 30

Maybe something like this could do the trick:

    public function convertToDatabaseValue($value, AbstractPlatform $platform): string
    {
        return $value ? (string) $value : null;
    }
    public function convertToPHPValue($value, AbstractPlatform $platform): CronExpression
    {
        return $value ? CronExpression::factory($value) : null;
    }

Update for Upcoming Doctrine/Dbal 4.0

The only thing not working right now are the Exception Handling:

doctrine/dbal@a2abc86#diff-93abf86e8ee8df45d8045fc5f4c82094d9e68b204351a8bc5811796803ce81d7L46-R48

  • ConversionException::conversionFailedInvalidType got removed, and is InvalidType::new now
  • ConversionException::conversionFailed is ValueNotConvertible::new
  • ConversionException::conversionFailedFormat is InvalidFormat::new

I need to find a nice way to handle this

i find it bad that they didn't deprecate the old functions first

Connect this with Symfony Scheduler?

would it make sense to have the Entries that have Cron Expression as Properties to be able to be used with Symfony Scheduler?

Currently i have written my own Cron Command, getting the Cron Expression from Entities, and then run a single command on them

The Question there is if this bundle should/could make this task easier?

Problem installing on Symfony 6.x

I tried to install the library with
composer require setono/cron-expression-bundle

but it conflicts with the Symfony version 6.x.

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires setono/cron-expression-bundle ^1.4 -> satisfiable by setono/cron-expression-bundle[v1.4.0].
    - setono/cron-expression-bundle v1.4.0 requires symfony/config ^4.4 || ^5.0 -> found symfony/config[v4.4.0, ..., v4.4.41, v5.0.0, ..., v5.4.8] but it conflicts with your root composer.json require (6.0.*).

Can you get the Bundle compatible with Symfony 6.x or update the decencies if already compatible? Thanks in advance.

Database is never in sync - schema is always about to be updated, requires comment

Hi, database is never in sync, it always wants to update. It is because of missing comment for sql, it cant recognize the type:

root@d463988465de:/var/www$ bin/console doctrine:schema:update --dump-sql --force

 The following SQL statements will be executed:

     ALTER TABLE task CHANGE schedule schedule VARCHAR(255) DEFAULT NULL;

 Updating database schema...

     1 query was executed


 [OK] Database schema updated successfully!


root@d463988465de:/var/www$ bin/console doctrine:schema:update --dump-sql --force

 The following SQL statements will be executed:

     ALTER TABLE task CHANGE schedule schedule VARCHAR(255) DEFAULT NULL;

 Updating database schema...

     1 query was executed


 [OK] Database schema updated successfully!

If i add to doctrine type this, it will start working:

    public function requiresSQLCommentHint(AbstractPlatform $platform)
    {
        return true;
    }
root@d463988465de:/var/www$ bin/console doctrine:schema:update --dump-sql --force

 The following SQL statements will be executed:

     ALTER TABLE task CHANGE schedule schedule VARCHAR(255) DEFAULT NULL COMMENT '(DC2Type:cron_expression)';

 Updating database schema...

     1 query was executed


 [OK] Database schema updated successfully!


root@d463988465de:/var/www$ bin/console doctrine:schema:update --dump-sql --force


 [OK] Nothing to update - your database is already in sync with the current entity
      metadata.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.