Merge pull request #8092 from eileenmcnaughton/CRM-18368
[civicrm-core.git] / CRM / Utils / System / Joomla.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2016
32 */
33
34 /**
35 * Joomla specific stuff goes here.
36 */
37 class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
38 /**
39 * Class constructor.
40 */
41 public function __construct() {
42 /**
43 * deprecated property to check if this is a drupal install. The correct method is to have functions on the UF classes for all UF specific
44 * functions and leave the codebase oblivious to the type of CMS
45 * @deprecated
46 * @var bool
47 */
48 $this->is_drupal = FALSE;
49 }
50
51 /**
52 * @inheritDoc
53 */
54 public function createUser(&$params, $mail) {
55 $baseDir = JPATH_SITE;
56 require_once $baseDir . '/components/com_users/models/registration.php';
57
58 $userParams = JComponentHelper::getParams('com_users');
59 $model = new UsersModelRegistration();
60 $ufID = NULL;
61
62 // get the default usertype
63 $userType = $userParams->get('new_usertype');
64 if (!$userType) {
65 $userType = 2;
66 }
67
68 if (isset($params['name'])) {
69 $fullname = trim($params['name']);
70 }
71 elseif (isset($params['contactID'])) {
72 $fullname = trim(CRM_Contact_BAO_Contact::displayName($params['contactID']));
73 }
74 else {
75 $fullname = trim($params['cms_name']);
76 }
77
78 // Prepare the values for a new Joomla user.
79 $values = array();
80 $values['name'] = $fullname;
81 $values['username'] = trim($params['cms_name']);
82 $values['password1'] = $values['password2'] = $params['cms_pass'];
83 $values['email1'] = $values['email2'] = trim($params[$mail]);
84
85 $lang = JFactory::getLanguage();
86 $lang->load('com_users', $baseDir);
87
88 $register = $model->register($values);
89
90 $ufID = JUserHelper::getUserId($values['username']);
91 return $ufID;
92 }
93
94 /**
95 * @inheritDoc
96 */
97 public function updateCMSName($ufID, $ufName) {
98 $ufID = CRM_Utils_Type::escape($ufID, 'Integer');
99 $ufName = CRM_Utils_Type::escape($ufName, 'String');
100
101 $values = array();
102 $user = JUser::getInstance($ufID);
103
104 $values['email'] = $ufName;
105 $user->bind($values);
106
107 $user->save();
108 }
109
110 /**
111 * Check if username and email exists in the Joomla db.
112 *
113 * @param array $params
114 * Array of name and mail values.
115 * @param array $errors
116 * Array of errors.
117 * @param string $emailName
118 * Field label for the 'email'.
119 */
120 public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
121 $config = CRM_Core_Config::singleton();
122
123 $dao = new CRM_Core_DAO();
124 $name = $dao->escape(CRM_Utils_Array::value('name', $params));
125 $email = $dao->escape(CRM_Utils_Array::value('mail', $params));
126 //don't allow the special characters and min. username length is two
127 //regex \\ to match a single backslash would become '/\\\\/'
128 $isNotValid = (bool) preg_match('/[\<|\>|\"|\'|\%|\;|\(|\)|\&|\\\\|\/]/im', $name);
129 if ($isNotValid || strlen($name) < 2) {
130 $errors['cms_name'] = ts('Your username contains invalid characters or is too short');
131 }
132
133 $JUserTable = &JTable::getInstance('User', 'JTable');
134
135 $db = $JUserTable->getDbo();
136 $query = $db->getQuery(TRUE);
137 $query->select('username, email');
138 $query->from($JUserTable->getTableName());
139 $query->where('(LOWER(username) = LOWER(\'' . $name . '\')) OR (LOWER(email) = LOWER(\'' . $email . '\'))');
140 $db->setQuery($query, 0, 10);
141 $users = $db->loadAssocList();
142
143 $row = array();
144 if (count($users)) {
145 $row = $users[0];
146 }
147
148 if (!empty($row)) {
149 $dbName = CRM_Utils_Array::value('username', $row);
150 $dbEmail = CRM_Utils_Array::value('email', $row);
151 if (strtolower($dbName) == strtolower($name)) {
152 $errors['cms_name'] = ts('The username %1 is already taken. Please select another username.',
153 array(1 => $name)
154 );
155 }
156 if (strtolower($dbEmail) == strtolower($email)) {
157 $resetUrl = str_replace('administrator/', '', $config->userFrameworkBaseURL) . 'index.php?option=com_users&view=reset';
158 $errors[$emailName] = ts('The email address %1 already has an account associated with it. <a href="%2">Have you forgotten your password?</a>',
159 array(1 => $email, 2 => $resetUrl)
160 );
161 }
162 }
163 }
164
165 /**
166 * @inheritDoc
167 */
168 public function setTitle($title, $pageTitle = NULL) {
169 if (!$pageTitle) {
170 $pageTitle = $title;
171 }
172
173 $template = CRM_Core_Smarty::singleton();
174 $template->assign('pageTitle', $pageTitle);
175
176 $document = JFactory::getDocument();
177 $document->setTitle($title);
178 }
179
180 /**
181 * @inheritDoc
182 */
183 public function appendBreadCrumb($breadCrumbs) {
184 $template = CRM_Core_Smarty::singleton();
185 $bc = $template->get_template_vars('breadcrumb');
186
187 if (is_array($breadCrumbs)) {
188 foreach ($breadCrumbs as $crumbs) {
189 if (stripos($crumbs['url'], 'id%%')) {
190 $args = array('cid', 'mid');
191 foreach ($args as $a) {
192 $val = CRM_Utils_Request::retrieve($a, 'Positive', CRM_Core_DAO::$_nullObject,
193 FALSE, NULL, $_GET
194 );
195 if ($val) {
196 $crumbs['url'] = str_ireplace("%%{$a}%%", $val, $crumbs['url']);
197 }
198 }
199 }
200 $bc[] = $crumbs;
201 }
202 }
203 $template->assign_by_ref('breadcrumb', $bc);
204 }
205
206 /**
207 * @inheritDoc
208 */
209 public function resetBreadCrumb() {
210 }
211
212 /**
213 * @inheritDoc
214 */
215 public function addHTMLHead($string = NULL) {
216 if ($string) {
217 $document = JFactory::getDocument();
218 $document->addCustomTag($string);
219 }
220 }
221
222 /**
223 * @inheritDoc
224 */
225 public function addStyleUrl($url, $region) {
226 if ($region == 'html-header') {
227 $document = JFactory::getDocument();
228 $document->addStyleSheet($url);
229 return TRUE;
230 }
231 return FALSE;
232 }
233
234 /**
235 * @inheritDoc
236 */
237 public function addStyle($code, $region) {
238 if ($region == 'html-header') {
239 $document = JFactory::getDocument();
240 $document->addStyleDeclaration($code);
241 return TRUE;
242 }
243 return FALSE;
244 }
245
246 /**
247 * @inheritDoc
248 */
249 public function url(
250 $path = NULL,
251 $query = NULL,
252 $absolute = FALSE,
253 $fragment = NULL,
254 $frontend = FALSE,
255 $forceBackend = FALSE
256 ) {
257 $config = CRM_Core_Config::singleton();
258 $separator = '&';
259 $Itemid = '';
260 $script = '';
261 $path = CRM_Utils_String::stripPathChars($path);
262
263 if ($config->userFrameworkFrontend) {
264 $script = 'index.php';
265 if (JRequest::getVar("Itemid")) {
266 $Itemid = "{$separator}Itemid=" . JRequest::getVar("Itemid");
267 }
268 }
269
270 if (isset($fragment)) {
271 $fragment = '#' . $fragment;
272 }
273
274 $base = $absolute ? $config->userFrameworkBaseURL : $config->useFrameworkRelativeBase;
275
276 if (!empty($query)) {
277 $url = "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$Itemid}{$separator}{$query}{$fragment}";
278 }
279 else {
280 $url = "{$base}{$script}?option=com_civicrm{$separator}task={$path}{$Itemid}{$fragment}";
281 }
282
283 // gross hack for joomla, we are in the backend and want to send a frontend url
284 if ($frontend && $config->userFramework == 'Joomla') {
285 // handle both joomla v1.5 and v1.6, CRM-7939
286 $url = str_replace('/administrator/index2.php', '/index.php', $url);
287 $url = str_replace('/administrator/index.php', '/index.php', $url);
288
289 // CRM-8215
290 $url = str_replace('/administrator/', '/index.php', $url);
291 }
292 elseif ($forceBackend) {
293 if (defined('JVERSION')) {
294 $joomlaVersion = JVERSION;
295 }
296 else {
297 $jversion = new JVersion();
298 $joomlaVersion = $jversion->getShortVersion();
299 }
300
301 if (version_compare($joomlaVersion, '1.6') >= 0) {
302 $url = str_replace('/index.php', '/administrator/index.php', $url);
303 }
304 }
305 return $url;
306 }
307
308 /**
309 * Set the email address of the user.
310 *
311 * @param object $user
312 * Handle to the user object.
313 */
314 public function setEmail(&$user) {
315 global $database;
316 $query = $db->getQuery(TRUE);
317 $query->select($db->quoteName('email'))
318 ->from($db->quoteName('#__users'))
319 ->where($db->quoteName('id') . ' = ' . $user->id);
320 $database->setQuery($query);
321 $user->email = $database->loadResult();
322 }
323
324 /**
325 * @inheritDoc
326 */
327 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
328 require_once 'DB.php';
329
330 $config = CRM_Core_Config::singleton();
331 $user = NULL;
332
333 if ($loadCMSBootstrap) {
334 $bootStrapParams = array();
335 if ($name && $password) {
336 $bootStrapParams = array(
337 'name' => $name,
338 'pass' => $password,
339 );
340 }
341 CRM_Utils_System::loadBootStrap($bootStrapParams, TRUE, TRUE, FALSE);
342 }
343
344 jimport('joomla.application.component.helper');
345 jimport('joomla.database.table');
346 jimport('joomla.user.helper');
347
348 $JUserTable = JTable::getInstance('User', 'JTable');
349
350 $db = $JUserTable->getDbo();
351 $query = $db->getQuery(TRUE);
352 $query->select('id, name, username, email, password');
353 $query->from($JUserTable->getTableName());
354 $query->where('(LOWER(username) = LOWER(\'' . $name . '\')) AND (block = 0)');
355 $db->setQuery($query, 0, 0);
356 $users = $db->loadObjectList();
357
358 $row = array();
359 if (count($users)) {
360 $row = $users[0];
361 }
362
363 $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))))));
364 if (!defined('JVERSION')) {
365 require $joomlaBase . '/libraries/cms/version/version.php';
366 $jversion = new JVersion();
367 define('JVERSION', $jversion->getShortVersion());
368 }
369
370 if (!empty($row)) {
371 $dbPassword = $row->password;
372 $dbId = $row->id;
373 $dbEmail = $row->email;
374
375 if (version_compare(JVERSION, '2.5.18', 'lt') ||
376 (version_compare(JVERSION, '3.0', 'ge') && version_compare(JVERSION, '3.2.1', 'lt'))
377 ) {
378 // now check password
379 list($hash, $salt) = explode(':', $dbPassword);
380 $cryptpass = md5($password . $salt);
381 if ($hash != $cryptpass) {
382 return FALSE;
383 }
384 }
385 else {
386 if (!JUserHelper::verifyPassword($password, $dbPassword, $dbId)) {
387 return FALSE;
388 }
389
390 //include additional files required by Joomla 3.2.1+
391 if (version_compare(JVERSION, '3.2.1', 'ge')) {
392 require_once $joomlaBase . '/libraries/cms/application/helper.php';
393 require_once $joomlaBase . '/libraries/cms/application/cms.php';
394 require_once $joomlaBase . '/libraries/cms/application/administrator.php';
395 }
396 }
397
398 CRM_Core_BAO_UFMatch::synchronizeUFMatch($row, $dbId, $dbEmail, 'Joomla');
399 $contactID = CRM_Core_BAO_UFMatch::getContactId($dbId);
400 if (!$contactID) {
401 return FALSE;
402 }
403 return array($contactID, $dbId, mt_rand());
404 }
405
406 return FALSE;
407 }
408
409 /**
410 * Set a init session with user object.
411 *
412 * @param array $data
413 * Array with user specific data.
414 */
415 public function setUserSession($data) {
416 list($userID, $ufID) = $data;
417 $user = new JUser($ufID);
418 $session = JFactory::getSession();
419 $session->set('user', $user);
420
421 parent::setUserSession($data);
422 }
423
424 /**
425 * FIXME: Do something
426 *
427 * @param string $message
428 */
429 public function setMessage($message) {
430 }
431
432 /**
433 * @param \string $username
434 * @param \string $password
435 *
436 * @return bool
437 */
438 public function loadUser($username, $password = NULL) {
439 $uid = JUserHelper::getUserId($username);
440 if (empty($uid)) {
441 return FALSE;
442 }
443 $contactID = CRM_Core_BAO_UFMatch::getContactId($uid);
444 if (!empty($password)) {
445 $instance = JFactory::getApplication('site');
446 $params = array(
447 'username' => $username,
448 'password' => $password,
449 );
450 //perform the login action
451 $instance->login($params);
452 }
453
454 $session = CRM_Core_Session::singleton();
455 $session->set('ufID', $uid);
456 $session->set('userID', $contactID);
457 return TRUE;
458 }
459
460 /**
461 * FIXME: Use CMS-native approach
462 */
463 public function permissionDenied() {
464 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
465 }
466
467 /**
468 * @inheritDoc
469 */
470 public function logout() {
471 session_destroy();
472 CRM_Utils_System::setHttpHeader("Location", "index.php");
473 }
474
475 /**
476 * @inheritDoc
477 */
478 public function getUFLocale() {
479 if (defined('_JEXEC')) {
480 $conf = JFactory::getConfig();
481 $locale = $conf->get('language');
482 return str_replace('-', '_', $locale);
483 }
484 return NULL;
485 }
486
487 /**
488 * @inheritDoc
489 */
490 public function setUFLocale($civicrm_language) {
491 // TODO
492 return TRUE;
493 }
494
495 /**
496 * @inheritDoc
497 */
498 public function getVersion() {
499 if (class_exists('JVersion')) {
500 $version = new JVersion();
501 return $version->getShortVersion();
502 }
503 else {
504 return 'Unknown';
505 }
506 }
507
508 /**
509 * Load joomla bootstrap.
510 *
511 * @param array $params
512 * with uid or name and password.
513 * @param bool $loadUser
514 * load cms user?.
515 * @param bool|\throw $throwError throw error on failure?
516 * @param null $realPath
517 * @param bool $loadDefines
518 *
519 * @return bool
520 */
521 public function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL, $loadDefines = TRUE) {
522 // Setup the base path related constant.
523 $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))))));
524
525 // load BootStrap here if needed
526 // We are a valid Joomla entry point.
527 if (!defined('_JEXEC') && $loadDefines) {
528 define('_JEXEC', 1);
529 define('DS', DIRECTORY_SEPARATOR);
530 define('JPATH_BASE', $joomlaBase . '/administrator');
531 require $joomlaBase . '/administrator/includes/defines.php';
532 }
533
534 // Get the framework.
535 if (file_exists($joomlaBase . '/libraries/import.legacy.php')) {
536 require $joomlaBase . '/libraries/import.legacy.php';
537 }
538 require $joomlaBase . '/libraries/import.php';
539 require $joomlaBase . '/libraries/joomla/event/dispatcher.php';
540 require $joomlaBase . '/configuration.php';
541
542 // Files may be in different places depending on Joomla version
543 if (!defined('JVERSION')) {
544 require $joomlaBase . '/libraries/cms/version/version.php';
545 $jversion = new JVersion();
546 define('JVERSION', $jversion->getShortVersion());
547 }
548
549 if (version_compare(JVERSION, '3.0', 'lt')) {
550 require $joomlaBase . '/libraries/joomla/environment/uri.php';
551 require $joomlaBase . '/libraries/joomla/application/component/helper.php';
552 }
553 else {
554 require $joomlaBase . '/libraries/cms.php';
555 require $joomlaBase . '/libraries/joomla/uri/uri.php';
556 }
557
558 jimport('joomla.application.cli');
559
560 // CRM-14281 Joomla wasn't available during bootstrap, so hook_civicrm_config never executes.
561 $config = CRM_Core_Config::singleton();
562 CRM_Utils_Hook::config($config);
563
564 return TRUE;
565 }
566
567 /**
568 * @inheritDoc
569 */
570 public function isUserLoggedIn() {
571 $user = JFactory::getUser();
572 return ($user->guest) ? FALSE : TRUE;
573 }
574
575 /**
576 * @inheritDoc
577 */
578 public function getLoggedInUfID() {
579 $user = JFactory::getUser();
580 return ($user->guest) ? NULL : $user->id;
581 }
582
583 /**
584 * @inheritDoc
585 */
586 public function getLoggedInUniqueIdentifier() {
587 $user = JFactory::getUser();
588 return $this->getUniqueIdentifierFromUserObject($user);
589 }
590
591 /**
592 * @inheritDoc
593 */
594 public function getUserIDFromUserObject($user) {
595 return !empty($user->id) ? $user->id : NULL;
596 }
597
598 /**
599 * @inheritDoc
600 */
601 public function getUniqueIdentifierFromUserObject($user) {
602 return ($user->guest) ? NULL : $user->email;
603 }
604
605 /**
606 * Get a list of all installed modules, including enabled and disabled ones
607 *
608 * @return array
609 * CRM_Core_Module
610 */
611 public function getModules() {
612 $result = array();
613
614 $db = JFactory::getDbo();
615 $query = $db->getQuery(TRUE);
616 $query->select('type, folder, element, enabled')
617 ->from('#__extensions')
618 ->where('type =' . $db->Quote('plugin'));
619 $plugins = $db->setQuery($query)->loadAssocList();
620 foreach ($plugins as $plugin) {
621 // question: is the folder really a critical part of the plugin's name?
622 $name = implode('.', array('joomla', $plugin['type'], $plugin['folder'], $plugin['element']));
623 $result[] = new CRM_Core_Module($name, $plugin['enabled'] ? TRUE : FALSE);
624 }
625
626 return $result;
627 }
628
629 /**
630 * @inheritDoc
631 */
632 public function getLoginURL($destination = '') {
633 $config = CRM_Core_Config::singleton();
634 $loginURL = $config->userFrameworkBaseURL;
635 $loginURL = str_replace('administrator/', '', $loginURL);
636 $loginURL .= 'index.php?option=com_users&view=login';
637
638 //CRM-14872 append destination
639 if (!empty($destination)) {
640 $loginURL .= '&return=' . urlencode(base64_encode($destination));
641 }
642 return $loginURL;
643 }
644
645 /**
646 * @inheritDoc
647 */
648 public function getLoginDestination(&$form) {
649 $args = NULL;
650
651 $id = $form->get('id');
652 if ($id) {
653 $args .= "&id=$id";
654 }
655 else {
656 $gid = $form->get('gid');
657 if ($gid) {
658 $args .= "&gid=$gid";
659 }
660 else {
661 // Setup Personal Campaign Page link uses pageId
662 $pageId = $form->get('pageId');
663 if ($pageId) {
664 $component = $form->get('component');
665 $args .= "&pageId=$pageId&component=$component&action=add";
666 }
667 }
668 }
669
670 $destination = NULL;
671 if ($args) {
672 // append destination so user is returned to form they came from after login
673 $args = 'reset=1' . $args;
674 $destination = CRM_Utils_System::url(CRM_Utils_System::currentPath(), $args, TRUE, NULL, FALSE, TRUE);
675 }
676
677 return $destination;
678 }
679
680 /**
681 * Determine the location of the CMS root.
682 *
683 * @return string|NULL
684 * local file system path to CMS root, or NULL if it cannot be determined
685 */
686 public function cmsRootPath() {
687 list($url, $siteName, $siteRoot) = $this->getDefaultSiteSettings();
688 $includePath = "$siteRoot/libraries/cms/version";
689 if (file_exists("$includePath/version.php")) {
690 return $siteRoot;
691 }
692 return NULL;
693 }
694
695 /**
696 * @inheritDoc
697 */
698 public function getDefaultSiteSettings($dir) {
699 $config = CRM_Core_Config::singleton();
700 $url = preg_replace(
701 '|/administrator|',
702 '',
703 $config->userFrameworkBaseURL
704 );
705 $siteRoot = preg_replace(
706 '|/media/civicrm/.*$|',
707 '',
708 $config->imageUploadDir
709 );
710 return array($url, NULL, $siteRoot);
711 }
712
713 /**
714 * @inheritDoc
715 */
716 public function getUserRecordUrl($contactID) {
717 $uid = CRM_Core_BAO_UFMatch::getUFId($contactID);
718 $userRecordUrl = NULL;
719 // if logged in user has user edit access, then allow link to other users joomla profile
720 if (JFactory::getUser()->authorise('core.edit', 'com_users')) {
721 return CRM_Core_Config::singleton()->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . $uid;
722 }
723 elseif (CRM_Core_Session::singleton()->get('userID') == $contactID) {
724 return CRM_Core_Config::singleton()->userFrameworkBaseURL . "index.php?option=com_admin&view=profile&layout=edit&id=" . $uid;
725 }
726 }
727
728 /**
729 * @inheritDoc
730 */
731 public function checkPermissionAddUser() {
732 if (JFactory::getUser()->authorise('core.create', 'com_users')) {
733 return TRUE;
734 }
735 }
736
737 /**
738 * Output code from error function.
739 * @param string $content
740 */
741 public function outputError($content) {
742 if (class_exists('JErrorPage')) {
743 $error = new Exception($content);
744 JErrorPage::render($error);
745 }
746 elseif (class_exists('JError')) {
747 JError::raiseError('CiviCRM-001', $content);
748 }
749 else {
750 parent::outputError($content);
751 }
752 }
753
754 /**
755 * Append Joomla js to coreResourcesList.
756 *
757 * @param array $list
758 */
759 public function appendCoreResources(&$list) {
760 $list[] = 'js/crm.joomla.js';
761 }
762
763 /**
764 * @inheritDoc
765 */
766 public function synchronizeUsers() {
767 $config = CRM_Core_Config::singleton();
768 if (PHP_SAPI != 'cli') {
769 set_time_limit(300);
770 }
771 $id = 'id';
772 $mail = 'email';
773 $name = 'name';
774
775 $JUserTable = &JTable::getInstance('User', 'JTable');
776
777 $db = $JUserTable->getDbo();
778 $query = $db->getQuery(TRUE);
779 $query->select($id . ', ' . $mail . ', ' . $name);
780 $query->from($JUserTable->getTableName());
781 $query->where($mail != '');
782
783 $db->setQuery($query);
784 $users = $db->loadObjectList();
785
786 $user = new StdClass();
787 $uf = $config->userFramework;
788 $contactCount = 0;
789 $contactCreated = 0;
790 $contactMatching = 0;
791 for ($i = 0; $i < count($users); $i++) {
792 $user->$id = $users[$i]->$id;
793 $user->$mail = $users[$i]->$mail;
794 $user->$name = $users[$i]->$name;
795 $contactCount++;
796 if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user,
797 $users[$i]->$id,
798 $users[$i]->$mail,
799 $uf,
800 1,
801 'Individual',
802 TRUE
803 )
804 ) {
805 $contactCreated++;
806 }
807 else {
808 $contactMatching++;
809 }
810 if (is_object($match)) {
811 $match->free();
812 }
813 }
814
815 return array(
816 'contactCount' => $contactCount,
817 'contactMatching' => $contactMatching,
818 'contactCreated' => $contactCreated,
819 );
820 }
821
822 }