*
* @return CRM_Core_DAO_OptionValue
*/
- public static function add(&$params, $ids) {
+ public static function add(&$params, $ids = array()) {
// CRM-10921: do not reset attributes to default if this is an update
//@todo consider if defaults are being set in the right place. 'dumb' defaults like
// these would be usefully set @ the api layer so they are visible to api users
}
if (!$found) {
- if ($config->userSystem->is_drupal) {
- $mail = 'mail';
- }
- elseif ($uf == 'WordPress') {
- $mail = 'user_email';
- }
- else {
- $mail = 'email';
- }
-
+ // Not sure why we're testing for this. Is there ever a case
+ // in which $user is not an object?
if (is_object($user)) {
- $params = array('email-Primary' => $user->$mail);
+ if ($config->userSystem->is_drupal) {
+ $primary_email = $uniqId;
+ }
+ elseif ($uf == 'WordPress') {
+ $primary_email = $user->user_email;
+ }
+ else {
+ $primary_email = $user->email;
+ }
+ $params = array('email-Primary' => $primary_email);
}
if ($ctype == 'Organization') {
if ($value) {
$value = CRM_Utils_File::addTrailingSlash($value);
if (isset($this->map[$k][2]) && in_array('mkdir', $this->map[$k][2])) {
- CRM_Utils_File::createDir($value);
+ if (!CRM_Utils_File::createDir($value, FALSE)) {
+ CRM_Core_Session::setStatus(ts('Failed to make directory (%1) at "%2". Please update the settings or file permissions.', array(
+ 1 => $k,
+ 2 => $value,
+ )));
+ }
}
if (isset($this->map[$k][2]) && in_array('restrict', $this->map[$k][2])) {
CRM_Utils_File::restrictAccess($value);
*
*/
public static function addOptionValue(&$params, &$groupParams, &$action, &$optionValueID) {
+ $ids = array();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
// checking if the group name with the given id or name (in $groupParams) exists
if (!empty($groupParams)) {
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2015
+ * $Id$
+ *
+ */
+class CRM_Extension_ClassLoader {
+
+ /**
+ * @var CRM_Extension_Mapper
+ */
+ protected $mapper;
+
+ /**
+ * @var CRM_Extension_Container_Interface
+ */
+ protected $container;
+
+ /**
+ * @var CRM_Extension_Manager
+ */
+ protected $manager;
+
+ /**
+ * @var \Composer\Autoload\ClassLoader
+ */
+ protected $loader;
+
+ /**
+ * CRM_Extension_ClassLoader constructor.
+ * @param \CRM_Extension_Mapper $mapper
+ * @param \CRM_Extension_Container_Interface $container
+ * @param \CRM_Extension_Manager $manager
+ */
+ public function __construct(\CRM_Extension_Mapper $mapper, \CRM_Extension_Container_Interface $container, \CRM_Extension_Manager $manager) {
+ $this->mapper = $mapper;
+ $this->container = $container;
+ $this->manager = $manager;
+ }
+
+ public function __destruct() {
+ if ($this->loader) {
+ $this->loader->unregister();
+ $this->loader = NULL;
+ }
+ }
+
+ /**
+ * Registers this instance as an autoloader.
+ * @return $this
+ */
+ public function register() {
+ // In pre-installation environments, don't bother with caching.
+ if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') || !defined('CIVICRM_DSN') || \CRM_Utils_System::isInUpgradeMode()) {
+ return $this->buildClassLoader()->register();
+ }
+
+ $envId = \CRM_Core_Config_Runtime::getId();
+ $file = CIVICRM_TEMPLATE_COMPILEDIR . "/CachedExtLoader.{$envId}.php";
+ if (file_exists($file)) {
+ $loader = require $file;
+ }
+ else {
+ $loader = $this->buildClassLoader();
+ $ser = serialize($loader);
+ file_put_contents($file,
+ sprintf("<?php\nreturn unserialize(%s);", var_export($ser, 1))
+ );
+ }
+ return $loader->register();
+ }
+
+ /**
+ * @return \Composer\Autoload\ClassLoader
+ * @throws \CRM_Extension_Exception
+ * @throws \Exception
+ */
+ public function buildClassLoader() {
+ $loader = new \Composer\Autoload\ClassLoader();
+
+ $statuses = $this->manager->getStatuses();
+ foreach ($statuses as $key => $status) {
+ if ($status !== CRM_Extension_Manager::STATUS_INSTALLED) {
+ continue;
+ }
+ $path = $this->mapper->keyToBasePath($key);
+ $info = $this->mapper->keyToInfo($key);
+ if (!empty($info->classloader)) {
+ foreach ($info->classloader as $mapping) {
+ switch ($mapping['type']) {
+ case 'psr4':
+ $loader->setPsr4($mapping['prefix'], $path . '/' . $mapping['path']);
+ break;
+ }
+ $result[] = $mapping;
+ }
+ }
+ }
+
+ return $loader;
+ }
+
+}
public $label = NULL;
public $file = NULL;
+ /**
+ * @var array
+ * Each item is a specification like:
+ * array('type'=>'psr4', 'namespace'=>'Foo\Bar', 'path'=>'/foo/bar').
+ */
+ public $classloader = array();
+
/**
* Load extension info an XML file.
*
}
ksort($this->urls);
}
+ elseif ($attr === 'classloader') {
+ $this->classloader = array();
+ foreach ($val->psr4 as $psr4) {
+ $this->classloader[] = array(
+ 'type' => 'psr4',
+ 'prefix' => (string) $psr4->attributes()->prefix,
+ 'path' => (string) $psr4->attributes()->path,
+ );
+ }
+ }
else {
$this->$attr = CRM_Utils_XML::xmlObjToArray($val);
}
private $browser = NULL;
private $downloader = NULL;
+ /**
+ * @var CRM_Extension_ClassLoader
+ * */
+ private $classLoader;
+
/**
* The URL of the remote extensions repository.
*
return $this->mapper;
}
+ /**
+ * @return \CRM_Extension_ClassLoader
+ */
+ public function getClassLoader() {
+ if ($this->classLoader === NULL) {
+ $this->classLoader = new CRM_Extension_ClassLoader($this->getMapper(), $this->getFullContainer(), $this->getManager());
+ }
+ return $this->classLoader;
+ }
+
/**
* Get the service for enabling and disabling extensions.
*
return $modules;
}
+ /**
+ * @inheritDoc
+ */
+ public function getUniqueIdentifierFromUserObject($user) {
+ return $user->get('mail')->value;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getUserIDFromUserObject($user) {
+ return $user->get('uid')->value;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function synchronizeUsers() {
+ $config = CRM_Core_Config::singleton();
+ if (PHP_SAPI != 'cli') {
+ set_time_limit(300);
+ }
+
+ $users = array();
+ $users = \Drupal::entityTypeManager()->getStorage('user')->loadByProperties();
+
+ $uf = $config->userFramework;
+ $contactCount = 0;
+ $contactCreated = 0;
+ $contactMatching = 0;
+ foreach ($users as $user) {
+ $mail = $user->get('mail')->value;
+ if (empty($mail)) {
+ continue;
+ }
+ $uid = $user->get('uid')->value;
+ $contactCount++;
+ if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $uid, $mail, $uf, 1, 'Individual', TRUE)) {
+ $contactCreated++;
+ }
+ else {
+ $contactMatching++;
+ }
+ if (is_object($match)) {
+ $match->free();
+ }
+ }
+
+ return array(
+ 'contactCount' => $contactCount,
+ 'contactMatching' => $contactMatching,
+ 'contactCreated' => $contactCreated,
+ );
+ }
+
}
\CRM_Core_DAO::init($runtime->dsn);
\CRM_Utils_Hook::singleton(TRUE);
\CRM_Extension_System::singleton(TRUE);
+ \CRM_Extension_System::singleton(TRUE)->getClassLoader()->register();
$c = new self();
\Civi::$statics[__CLASS__]['container'] = $c->loadContainer();
function cv($cmd, $decode = 'json') {
$cmd = 'cv ' . $cmd;
$descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => STDERR);
- $env = $_ENV + array('CV_OUTPUT' => 'json');
- $process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__, $env);
+ $oldOutput = getenv('CV_OUTPUT');
+ putenv("CV_OUTPUT=json");
+ $process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__);
+ putenv("CV_OUTPUT=$oldOutput");
fclose($pipes[0]);
$result = stream_get_contents($pipes[1]);
fclose($pipes[1]);