CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Warnings when i enable extension generated by civix
Pages: [1]

Author Topic: Warnings when i enable extension generated by civix  (Read 1356 times)

rubofvil

  • I’m new here
  • *
  • Posts: 23
  • Karma: 1
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 7
  • MySQL version: mysql 5.1
  • PHP version: php 5.2
Warnings when i enable extension generated by civix
February 25, 2013, 03:51:53 am
When i generate a extension with civix command:
civix generate:module com.extension.pruebaactivar

I have next warnings when i enable the extension.

Warning: Invalid argument supplied for foreach() in _pruebaactivar_civix_civicrm_xmlMenu() (line 34 of /data/disk/rpineda/static/repositories/com.extension.pruebaactivar/pruebaactivar.civix.php).

Warning: Invalid argument supplied for foreach() in _pruebaactivar_civix_find_files() (line 118 of /data/disk/rpineda/static/repositories/com.extension.pruebaactivar/pruebaactivar.civix.php).


Thank you in advance.

Versions
civix --version Symfony version 2.1.0 - app/dev/debug
Drupal 7.19
CIVICRM 4.2

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Warnings when i enable extension generated by civix
February 25, 2013, 02:39:09 pm
Interesting. Both of those errors appear to involve a statement like:

foreach (glob(...) as $file) { ... }

Evidently, the glob() call is not returning an array. According to the glob documentation ( http://php.net/glob ), this should return an array regardless of whether a file matches or not -- the only time it should return FALSE is when there's an "error" (not specified, but maybe a permission error or I/O error). However, there's this ambiguous caveat:

"On some systems it is impossible to distinguish between empty match and an error."

Which I guess means that we can't count on glob() to return an array in normal conditions.

Perhaps you could try changing _pruebaactivar_civix_civicrm_xmlMenu()  to one of these:

Code: [Select]
function _pruebaactivar_civix_civicrm_xmlMenu(&$files) {
  foreach ((array)glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
    $files[] = $file;
  }
}

or

Code: [Select]
function _pruebaactivar_civix_civicrm_xmlMenu(&$files) {
  $glob = glob(__DIR__ . '/xml/Menu/*.xml');
  if (is_array($glob)) {
    foreach ($glob as $file) {
      $files[] = $file;
    }
  }
}

If that works, let me know so I can update the template used for new extensions.

Out of curiosity, what environment is this running under? (Based on the php.net/glob caveat and the file paths, it doesn't seem like a typical LAMP deployment.)

rubofvil

  • I’m new here
  • *
  • Posts: 23
  • Karma: 1
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 7
  • MySQL version: mysql 5.1
  • PHP version: php 5.2
Re: Warnings when i enable extension generated by civix
February 26, 2013, 03:39:19 am
Trank you for your fast reply.

First option:
function _customreportmembership_civix_civicrm_xmlMenu(&$files) {
  foreach ((array)glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
    $files[] = $file;
  }
}


Make next warnings
Warning: simplexml_load_file(): I/O warning : failed to load external entity "" in CRM_Core_Menu::read() (line 98 of /data/disk/rpineda/static/plataformas/m/sites/all/modules/civicrm/CRM/Core/Menu.php).
Warning: Invalid argument supplied for foreach() in CRM_Core_Menu::read() (line 99 of /data/disk/rpineda/static/plataformas/m/sites/all/modules/civicrm/CRM/Core/Menu.php).
Warning: Invalid argument supplied for foreach() in _customreportmembership_civix_find_files() (line 118 of /data/disk/rpineda/static/repositories/customreportmembership/customreportmembership.civix.php).



Second option:
function _customreportmembership_civix_civicrm_xmlMenu(&$files) {
  $glob = glob(__DIR__ . '/xml/Menu/*.xml');
  if (is_array($glob)) {
    foreach ($glob as $file) {
      $files[] = $file;
    }
  }


Next warnings:
Warning: Invalid argument supplied for foreach() in _customreportmembership_civix_find_files() (line 121 of /data/disk/rpineda/static/repositories/customreportmembership/customreportmembership.civix.php).
(line 121  foreach (glob("$subdir/$pattern") as $match) {)


The environment is Aegir.

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Warnings when i enable extension generated by civix
February 26, 2013, 12:39:57 pm
I've updated the template for '*.civix.php' to deal with variations in glob() behavior. It applies the fix to both spots (circa lines 34 and 118)

You can try replacing pruebaactivar.civix.php with the attached file (based on the new template). Alternatively, you can regenerate the file yourself:

1. Update civix (e.g. go to the civix dir and run "git pull")
2. Go the extension parent dir
3. Rerun "civix generate:module com.extension.pruebaactivar" . This should replace the pruebaactivar.civix.php, preserve the pruebaactivar.php, and safely touch the info.xml.

rubofvil

  • I’m new here
  • *
  • Posts: 23
  • Karma: 1
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 7
  • MySQL version: mysql 5.1
  • PHP version: php 5.2
Re: Warnings when i enable extension generated by civix
February 27, 2013, 01:56:56 am
Works!! Thank you.

Pd. In this posts i don't use tag code because i have problem's with permissions of links(The editor confuse path with links).

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • Warnings when i enable extension generated by civix

This forum was archived on 2017-11-26.