fuel / oil

Fuel PHP Framework - Fuel v1.x Oil command-line package
http://fuelphp.com/docs/packages/oil/intro.html
106 stars 67 forks source link

oil refine fromdb:scaffold --all #253

Open stvowi opened 7 years ago

stvowi commented 7 years ago

...don't work. I tested with WAMP server and PHP 5.6 and Fuel 1.9 dev

I got an exception in scaffold.php Line 63: array to string conversersion.

I fixed it with...

        foreach (array_slice($args, 1) as $arg)
        {
            if (is_string($arg))
            {
                // Parse the argument for each field in a pattern of name:type[constraint]
                preg_match(static::$fields_regex, $arg, $matches);

                if ( ! isset($matches[1]))
                {
                    throw new Exception('Unable to determine the field definition for "'.$arg.'". Ensure they are name:type');
                }

                $data['fields'][] = array(
                    'name'       => \Str::lower($matches[1]),
                    'type'       => isset($matches[2]) ? $matches[2] : 'string',
                    'constraint' => isset($matches[4]) ? $matches[4] : null,
                );              
            }
            else
            {
                $data['fields'][] = array(
                    'name'       => \Str::lower($arg['name']),
                    'type'       => $arg['type'],
                    'constraint' => $arg['constraint'],
                );
            }           
        }

and than I got a new exception in generate.php (line 2040)....GlobIterator throws LogicException There is a Problem with the GlobIterator. (see: https://bugs.php.net/bug.php?id=55701)

WanWizard commented 7 years ago

The Globiterator issue was fixed in 5.6, so this suggests your installation isn't up to date (current version is 5.6.30).

stvowi commented 7 years ago

I thought, Fuel PHP needs only PHP 5.3.0 .

Okay, than we come to the next problem.

There will generated 2 id fields in the model if the database table have the id field.

Sample:

<?php
use Orm\Model;

class Model_Object extends Model
{
    protected static $_properties = array(
        'id',
        'id',
        'label',
        'created_at',
        'updated_at',
    );

    protected static $_observers = array(
        'Orm\Observer_CreatedAt' => array(
            'events' => array('before_insert'),
            'mysql_timestamp' => false,
        ),
        'Orm\Observer_UpdatedAt' => array(
            'events' => array('before_save'),
            'mysql_timestamp' => false,
        ),
    );

    public static function validate($factory)
    {
        $val = Validation::forge($factory);
        $val->add_field('id', 'Id', 'required|valid_string[numeric]');
        $val->add_field('label', 'Label', 'required|max_length[500]');

        return $val;
    }

}

BTW, why will generated the observer, if I don't have created_at/ updated_at fields not in the database table?

WanWizard commented 7 years ago

PHP 5.3.3+ to be exact. But that doesn't mean it contains workarounds for PHP bugs for any released version after that.

I'll have a look at where the double "id" fields comes from. Just to check, your table only contains an 'id' field (as int, PK) and a label field (char of some sort)?