Answers.Body: <p><code>civix generate:entity</code> is experimental and, last I checked, broken.</p>
  
  <p>When I need to do this, my approach is as follows:</p>
  
  <ol>
  <li>create my XML file for the new entity</li>
  <li>run a helper script to generate the SQL and DAO</li>
  </ol>
  
  <p>Have a look at the <a href="https://github.com/civicrm/org.civicrm.volunteer/tree/master/bin" rel="nofollow noreferrer">helper files</a> in CiviVolunteer for guidance; they should work for any project with minimal modification.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T18:11:43.757Z
Answers.Text: `generate:entity` isn't actually broken (for me at least): it created the appropriate folder, a few PHP files and even the XML, I just needed to add more fields to it. I believe it is [mentioned as experimental and incomplete](https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-entity) because ideally it would also generate the DAO and SQL files. I saw the helper script you linked and realized it's a short version of the core's setup.sh, calling `php GenCode.php` at the end, which also fails due to the missing files I mentioned above. Anyway, thank you for the suggestion Frank.
Answers.UserDisplayName: Armfoot
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-21T13:59:57.630Z
Answers.LastActivityDate: 2017-06-21T13:59:57.630Z
Answers.UserDisplayName: universalhandle
Answers.Body: <p><code>civix</code> is now capable of generating the SQL and DAO with: <code>civix generate:entity-boilerplate</code>.  <a href="https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-entity" rel="nofollow noreferrer">The civix documentation</a> gives more info.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-05T21:35:33.880Z
Answers.LastActivityDate: 2018-09-05T21:35:33.880Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>I have been trying to generate DAO and SQL files for an entity I created with <code>civix generate:entity ...</code> according to the <a href="https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-entity" rel="nofollow noreferrer">documentation ("Add a new entity" - 4.d.)</a>.</p>
  
  <p>Using the latest civicrm-core clone (latest commit <a href="https://github.com/civicrm/civicrm-core/commit/e637260340bde2c4426b520a705ec86465ef7015" rel="nofollow noreferrer">e637260</a>) I:</p>
  
  <ol>
  <li>ran <code>composer install</code> on the root (civiroot);</li>
  <li>verified that the vendor folder has the same packages that come along with, for example, CiviCRM 4.7.20 for Drupal 7.x (<code>sites/all/modules/civicrm/vendor</code>);</li>
  <li>copied the new entity's schema to the <code>xml/schema</code> folder;</li>
  <li>altered the <code>Schema.xml</code> itself to include this entity.</li>
  </ol>
  
  <p>However, after running <code>bash bin/setup.sh -g</code> or <code>php xml/GenCode.php</code> this comes up:</p>
  
  <blockquote>
    <p>Fatal error: require_once(): Failed opening required 'Log.php' </p>
  </blockquote>
  
  <p>I.e. <code>&lt;root&gt;/CRM/Core/Config.php</code> is expecting:</p>
  
  <pre><code>require_once 'Log.php';
  require_once 'Mail.php';
  </code></pre>
  
  <p>I searched for a while and I could not find these files, so I just thought of trying it out without these lines from <code>Config.php</code>, but once I rerun I got:</p>
  
  <blockquote>
    <p>Notice: Use of undefined constant <em>PEAR_ERROR_CALLBACK</em> - assumed 'PEAR_ERROR_CALLBACK' in <code>&lt;root&gt;/CRM/Core/TemporaryErrorScope.php</code> on line 49</p>
    
    <p>Notice:  Undefined index: _PEAR_default_error_mode
    in <code>&lt;root&gt;/CRM/Core/TemporaryErrorScope.php</code> on line 74</p>
    
    <p>Notice:  Undefined index: _PEAR_default_error_options
    in <code>&lt;root&gt;/CRM/Core/TemporaryErrorScope.php</code> on line 75</p>
    
    <p>Warning:  require_once(<strong>PEAR/ErrorStack.php</strong>): failed to open
    stream: No such file or directory in <code>&lt;root&gt;/CRM/Core/Error.php</code> on line 36</p>
    
    <p>Fatal error:  require_once(): <strong>Failed opening required
    'PEAR/ErrorStack.php'</strong> (include_path='<code>.:&lt;root&gt;:&lt;root&gt;/packages:&lt;root&gt;/vendor/tecnickcom:&lt;root&gt;/vendor/phpseclib/phpseclib/phpseclib:&lt;root&gt;/vendor/pear/pear_exception:&lt;root&gt;/vendor/pear/auth_sasl:&lt;root&gt;/vendor/pear/validate_finance_creditcard:.:../packages:..</code>')
    in /CRM/Core/Error.php on line 36</p>
  </blockquote>
  
  <p>I did find a PEAR folder but it is in <code>&lt;root&gt;/vendor/pear/pear_exception/PEAR</code>, without any <code>ErrorStack.php</code> file.</p>
  
  <p>I also found a couple of related questions in here:</p>
  
  <ul>
  <li><a href="https://civicrm.stackexchange.com/questions/3922/how-to-automatically-generate-dao-classes-for-my-db-tables">How to automatically generate DAO classes for my DB tables</a></li>
  <li><a href="https://civicrm.stackexchange.com/questions/3534/how-do-i-add-a-new-table-to-my-extension?rq=1">How do I add a new table to my extension?</a></li>
  </ul>
  
  <p>In the last one, I understand that people seem to run the code generator without such problems.</p>
  
  <p>I apologize the long question, <strong>TLDR;</strong></p>
  
  <ul>
  <li>what am I missing? What does <code>GenCode.php</code> need in order to run properly?</li>
  <li>is there another way to generate DAO and SQL files for new entities?</li>
  </ul>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-18T15:41:34.273Z
Comments.Text: Hi @Armfoot, did you already try to install buildkit to create a development instance (See https://docs.civicrm.org/dev/en/latest/tools/buildkit/).  I installed my development machine this way and the setup script works.
Comments.UserDisplayName: Kainuk - CiviCooP
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-20T18:16:54.150Z
Comments.Text: Thank you @Kainuk. Although the `setup.sh` script runs for me as well (in a clean core clone, without even buildkit), the generation option (`-g`) does not. I indeed added the buildkit bin folder to the relevant environment variable (PATH), but even so, the files I mentioned continue to be required. I am still considering if any of the buildkit scripts would generate these missing files...
Comments.UserDisplayName: Armfoot
Tags: <mysql><civicrm-entity><core><civix>
Title: Difficulties generating an entity's DAO and SQL for a new extension
ThreadText: # Difficulties generating an entity's DAO and SQL for a new extension
  
  (Asked by: username_0 on 2017-06-16)
  
  I have been trying to generate DAO and SQL files for an entity I created with `civix generate:entity ...` according to the [documentation ("Add a new entity" - 4.d.)](https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-entity).
  
  Using the latest civicrm-core clone (latest commit [e637260](https://github.com/civicrm/civicrm-core/commit/e637260340bde2c4426b520a705ec86465ef7015)) I:
  
  1. ran `composer install` on the root (civiroot);
  2. verified that the vendor folder has the same packages that come along with, for example, CiviCRM 4.7.20 for Drupal 7.x (`sites/all/modules/civicrm/vendor`);
  3. copied the new entity's schema to the `xml/schema` folder;
  4. altered the `Schema.xml` itself to include this entity.
  
  However, after running `bash bin/setup.sh -g` or `php xml/GenCode.php` this comes up:
  
  > Fatal error: require\_once(): Failed opening required 'Log.php'
  
  I.e. `<root>/CRM/Core/Config.php` is expecting:
  
  ```
  require_once 'Log.php';
  require_once 'Mail.php';
  
  ```
  
  I searched for a while and I could not find these files, so I just thought of trying it out without these lines from `Config.php`, but once I rerun I got:
  
  > Notice: Use of undefined constant *PEAR\_ERROR\_CALLBACK* - assumed 'PEAR\_ERROR\_CALLBACK' in `<root>/CRM/Core/TemporaryErrorScope.php` on line 49
  >
  > Notice: Undefined index: \_PEAR\_default\_error\_mode
  > in `<root>/CRM/Core/TemporaryErrorScope.php` on line 74
  >
  > Notice: Undefined index: \_PEAR\_default\_error\_options
  > in `<root>/CRM/Core/TemporaryErrorScope.php` on line 75
  >
  > Warning: require\_once(**PEAR/ErrorStack.php**): failed to open
  > stream: No such file or directory in `<root>/CRM/Core/Error.php` on line 36
  >
  > Fatal error: require\_once(): **Failed opening required
  > 'PEAR/ErrorStack.php'** (include\_path='`.:<root>:<root>/packages:<root>/vendor/tecnickcom:<root>/vendor/phpseclib/phpseclib/phpseclib:<root>/vendor/pear/pear_exception:<root>/vendor/pear/auth_sasl:<root>/vendor/pear/validate_finance_creditcard:.:../packages:..`')
  > in /CRM/Core/Error.php on line 36
  
  I did find a PEAR folder but it is in `<root>/vendor/pear/pear_exception/PEAR`, without any `ErrorStack.php` file.
  
  I also found a couple of related questions in here:
  
  * [How to automatically generate DAO classes for my DB tables](https://civicrm.stackexchange.com/questions/3922/how-to-automatically-generate-dao-classes-for-my-db-tables)
  * [How do I add a new table to my extension?](https://civicrm.stackexchange.com/questions/3534/how-do-i-add-a-new-table-to-my-extension?rq=1)
  
  In the last one, I understand that people seem to run the code generator without such problems.
  
  I apologize the long question, **TLDR;**
  
  * what am I missing? What does `GenCode.php` need in order to run properly?
  * is there another way to generate DAO and SQL files for new entities?
  
  **Tags:** mysql, civicrm-entity, core, civix
  
  > **Comments:**
  > **username_1**: Hi @username_0, did you already try to install buildkit to create a development instance (See https://docs.civicrm.org/dev/en/latest/tools/buildkit/).  I installed my development machine this way and the setup script works.  
  > **username_0**: Thank you @username_1. Although the `setup.sh` script runs for me as well (in a clean core clone, without even buildkit), the generation option (`-g`) does not. I indeed added the buildkit bin folder to the relevant environment variable (PATH), but even so, the files I mentioned continue to be required. I am still considering if any of the buildkit scripts would generate these missing files...  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-06-21. Score: 1
  
  `civix generate:entity` is experimental and, last I checked, broken.
  
  When I need to do this, my approach is as follows:
  
  1. create my XML file for the new entity
  2. run a helper script to generate the SQL and DAO
  
  Have a look at the [helper files](https://github.com/civicrm/org.civicrm.volunteer/tree/master/bin) in CiviVolunteer for guidance; they should work for any project with minimal modification.
  
  > **Comments:**
  > **username_0**: `generate:entity` isn't actually broken (for me at least): it created the appropriate folder, a few PHP files and even the XML, I just needed to add more fields to it. I believe it is [mentioned as experimental and incomplete](https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-entity) because ideally it would also generate the DAO and SQL files. I saw the helper script you linked and realized it's a short version of the core's setup.sh, calling `php GenCode.php` at the end, which also fails due to the missing files I mentioned above. Anyway, thank you for the suggestion Frank.  
  
  ---
  
  ### Answer by username_3 on 2018-09-05. Score: 1
  
  `civix` is now capable of generating the SQL and DAO with: `civix generate:entity-boilerplate`. [The civix documentation](https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-entity) gives more info.
  
  
  ---
  
  