Overview

Documentation about izfixtures module
=====================================

Goal
----

This module allows you to quickly load fixtures data in your tables; in developpement mode


Licence
-------

izfixtures is provided under the terms of the LGPL Licence


Install
-------

* Copy the mmodule in your application
* If you run jelix 1.2, you must install the module:
  - add "izfixtures.access=2" in the [modules] section of the defaultconfig.ini.php file
  - then run this jelix-scripts command: "php jelix.php installmodule izfixtures cmdline"
  
If you don't have a cmdline.php entrypoint in your scripts/ folder, create one, using this command:
  "php jelix.php createentrypoint -type cmdline cmdline"

Finally clear temp directory, to make sure everything is ok:
  "php jelix.php cleartemp"
* Create a data.js or data.yml file into var/fixtures/ of your application, depending on the format you want to use
* Add truncate method in each dao files needed :

    <method name="truncate" type="php">
        <body><![CDATA[ 
            $query = 'TRUNCATE TABLE '. $this->_tables[$this->_primaryTable]['realname'];
            $this->_conn->exec($query);
            ]]></body> 
    </method>


Usage
-----

$php cmdline.php izfixtures~default:populate [-profile name]

Load fixtures data into tables

-profile (optional) : connection profile to the database.

Create a fixtures file named data.yml or data.js (depending the format you use) in var/fixtures/ (create it) of your application.
The script detect the format from the extension of the data fixtures file


Example
---------------------

You have the following 'moduleFoo~news' dao :

    <?xml version="1.0" encoding="UTF-8"?>
    <dao xmlns="http://jelix.org/ns/dao/1.0">
        <datasources>
            <primarytable name="iz_news" realname="iz_news" primarykey="id" />
        </datasources>
        <record>
            <property name="id" fieldname="id" datatype="autoincrement"/>
            <property name="title" fieldname="title" datatype="string" required="true" maxlength="64"/>
            <property name="slug" fieldname="slug" datatype="string" required="true" maxlength="64"/>
            <property name="content" fieldname="content" datatype="text" required="true"/>
            <property name="online" fieldname="online" datatype="int" required="true"/>
            <property name="created_at" fieldname="created_at" datatype="datetime" required="true"/>
        </record>
        <factory>
            <method name="truncate" type="php">
                <body><![CDATA[ 
                    $query = 'TRUNCATE TABLE '. $this->_primaryTable;
                    $this->_conn->exec($query);
                    ]]></body> 
            </method>
        </factory>
    </dao>

In data.js (json format):

    { "fooModule~news": [
            {"id": 1,
            "title": "My first news json",
            "slug": "my-first-news-json",
            "content": "This is my first news json",
            "online": 1,
            "created_at": "<?php return date('Y-m-d H:i:s', time() - 3600*24*15); ?>"
            },
            { "id": 2,
            "title": "My second news json",
            "slug": "my-second-news-json",
            "content": "This is my second news json",
            "online": 1,
            "created_at": "<?php return date('Y-m-d H:i:s', time() - 3600*24*10); ?>"
            },
            {"id": 3,
            "title": "My third news",
            "slug": "my-third-news",
            "content": "This is my third news",
            "online": 0,
            "created_at": "<?php return date('Y-m-d H:i:s', time() - 3600*24*5); ?>"
           },{
            "id": 4,
            "title": "My fourth news",
            "slug": "my-fourth-news",
            "content": "This is my fourth news",
            "online": 1,
            "created_at": "<?php return date('Y-m-d H:i:s'); ?>"
          }
        ]
    }


In data.yml (yaml format) :

    fooModule~news:
      -
        id: 1
        title: My first news
        slug: my-first-news
        content: This is my first news
        online: 1
        created_at: "<?php return date('Y-m-d H:i:s', time() - 3600*24*15); ?>"
      -
        id: 2
        title: My second news
        slug: my-second-news
        content: This is my second news
        online: 1
        created_at: "<?php return date('Y-m-d H:i:s', time() - 3600*24*10); ?>"
      -
        id: 3
        title: My third news
        slug: my-third-news
        content: This is my third news
        online: 0
        created_at: "<?php return date('Y-m-d H:i:s', time() - 3600*24*5); ?>"
      -
        id: 4
        title: My fourth news
        slug: my-fourth-news
        content: This is my fourth news
        online: 1
        created_at: "<?php return date('Y-m-d H:i:s'); ?>"