2

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.).

Using the latest civicrm-core clone (latest commit e637260) 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:

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?
  • 1
    Hi @Armfoot, did you already try to install buildkit to create a development instance (See docs.civicrm.org/dev/en/latest/tools/buildkit). I installed my development machine this way and the setup script works. – Kainuk - CiviCooP Jun 18 '17 at 15:41
  • 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... – Armfoot Jun 20 '17 at 18:16
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 in CiviVolunteer for guidance; they should work for any project with minimal modification.

  • 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 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. – Armfoot Jun 22 '17 at 18:11
1

civix is now capable of generating the SQL and DAO with: civix generate:entity-boilerplate. The civix documentation gives more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.