* Process the form submission.
*/
public function postProcess() {
- $result = CRM_Core_BAO_CMSUser::synchronize();
+ $result = CRM_Core_Config::singleton()->userSystem->synchronizeUsers();
$status = ts('Checked one user record.',
array(
*/
class CRM_Core_BAO_CMSUser {
- /**
- * Synchronize CMS users with CiviCRM contacts.
- *
- * @return array
- */
- public static function synchronize() {
- $config = CRM_Core_Config::singleton();
-
- // Build an array of rows from UF users table.
- $rows = array();
- if ($config->userSystem->is_drupal == '1') {
- $id = 'uid';
- $mail = 'mail';
- $name = 'name';
-
- $result = db_query("SELECT uid, mail, name FROM {users} where mail != ''");
-
- if ($config->userFramework == 'Drupal') {
- while ($row = $result->fetchAssoc()) {
- $rows[] = $row;
- }
- }
- elseif ($config->userFramework == 'Drupal6') {
- while ($row = db_fetch_array($result)) {
- $rows[] = $row;
- }
- }
- }
- elseif ($config->userFramework == 'Joomla') {
- $id = 'id';
- $mail = 'email';
- $name = 'name';
- // TODO: Insert code here to populate $rows for Joomla;
- }
- elseif ($config->userFramework == 'WordPress') {
- $id = 'ID';
- $mail = 'user_email';
- }
- else {
- CRM_Core_Error::fatal('CMS user creation not supported for this framework');
- }
-
- if (PHP_SAPI != 'cli') {
- set_time_limit(300);
- }
-
- if ($config->userSystem->is_drupal == '1') {
- $user = new StdClass();
- $uf = $config->userFramework;
- $contactCount = 0;
- $contactCreated = 0;
- $contactMatching = 0;
- foreach ($rows as $row) {
- $user->$id = $row[$id];
- $user->$mail = $row[$mail];
- $user->$name = $row[$name];
- $contactCount++;
- if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $row[$id], $row[$mail], $uf, 1, 'Individual', TRUE)) {
- $contactCreated++;
- }
- else {
- $contactMatching++;
- }
- if (is_object($match)) {
- $match->free();
- }
- }
- }
- elseif ($config->userFramework == 'Joomla') {
-
- $JUserTable = &JTable::getInstance('User', 'JTable');
-
- $db = $JUserTable->getDbo();
- $query = $db->getQuery(TRUE);
- $query->select($id . ', ' . $mail . ', ' . $name);
- $query->from($JUserTable->getTableName());
- $query->where($mail != '');
-
- $db->setQuery($query, 0, $limit);
- $users = $db->loadObjectList();
-
- $user = new StdClass();
- $uf = $config->userFramework;
- $contactCount = 0;
- $contactCreated = 0;
- $contactMatching = 0;
- for ($i = 0; $i < count($users); $i++) {
- $user->$id = $users[$i]->$id;
- $user->$mail = $users[$i]->$mail;
- $user->$name = $users[$i]->$name;
- $contactCount++;
- if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user,
- $users[$i]->$id,
- $users[$i]->$mail,
- $uf,
- 1,
- 'Individual',
- TRUE
- )
- ) {
- $contactCreated++;
- }
- else {
- $contactMatching++;
- }
- if (is_object($match)) {
- $match->free();
- }
- }
- }
- elseif ($config->userFramework == 'WordPress') {
- $uf = $config->userFramework;
- $contactCount = 0;
- $contactCreated = 0;
- $contactMatching = 0;
-
- global $wpdb;
- $wpUserIds = $wpdb->get_col("SELECT $wpdb->users.ID FROM $wpdb->users");
-
- foreach ($wpUserIds as $wpUserId) {
- $wpUserData = get_userdata($wpUserId);
- $contactCount++;
- if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($wpUserData,
- $wpUserData->$id,
- $wpUserData->$mail,
- $uf,
- 1,
- 'Individual',
- TRUE
- )
- ) {
- $contactCreated++;
- }
- else {
- $contactMatching++;
- }
- if (is_object($match)) {
- $match->free();
- }
- }
- }
-
- return array(
- 'contactCount' => $contactCount,
- 'contactMatching' => $contactMatching,
- 'contactCreated' => $contactCreated,
- );
- }
-
/**
* Create CMS user using Profile.
*
header("$name: $value");
}
+ /**
+ * Create CRM contacts for all existing CMS users
+ *
+ * @return array
+ * @throws \Exception
+ */
+ public function synchronizeUsers() {
+ throw new Exception('CMS user creation not supported for this framework');
+ return array();
+ }
+
}
drupal_add_http_header($name, $value);
}
+ /**
+ * @inheritDoc
+ */
+ public function synchronizeUsers() {
+ $config = CRM_Core_Config::singleton();
+ if (PHP_SAPI != 'cli') {
+ set_time_limit(300);
+ }
+ $rows = array();
+ $id = 'uid';
+ $mail = 'mail';
+ $name = 'name';
+
+ $result = db_query("SELECT uid, mail, name FROM {users} where mail != ''");
+
+ while ($row = $result->fetchAssoc()) {
+ $rows[] = $row;
+ }
+
+ $user = new StdClass();
+ $uf = $config->userFramework;
+ $contactCount = 0;
+ $contactCreated = 0;
+ $contactMatching = 0;
+ foreach ($rows as $row) {
+ $user->$id = $row[$id];
+ $user->$mail = $row[$mail];
+ $user->$name = $row[$name];
+ $contactCount++;
+ if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $row[$id], $row[$mail], $uf, 1, 'Individual', TRUE)) {
+ $contactCreated++;
+ }
+ else {
+ $contactMatching++;
+ }
+ if (is_object($match)) {
+ $match->free();
+ }
+ }
+
+ return array(
+ 'contactCount' => $contactCount,
+ 'contactMatching' => $contactMatching,
+ 'contactCreated' => $contactCreated,
+ );
+ }
+
}
drupal_set_header("$name: $value");
}
+ /**
+ * @inheritDoc
+ */
+ public function synchronizeUsers() {
+ $config = CRM_Core_Config::singleton();
+ if (PHP_SAPI != 'cli') {
+ set_time_limit(300);
+ }
+ $rows = array();
+ $id = 'uid';
+ $mail = 'mail';
+ $name = 'name';
+
+ $result = db_query("SELECT uid, mail, name FROM {users} where mail != ''");
+
+ while ($row = db_fetch_array($result)) {
+ $rows[] = $row;
+ }
+
+ $user = new StdClass();
+ $uf = $config->userFramework;
+ $contactCount = 0;
+ $contactCreated = 0;
+ $contactMatching = 0;
+ foreach ($rows as $row) {
+ $user->$id = $row[$id];
+ $user->$mail = $row[$mail];
+ $user->$name = $row[$name];
+ $contactCount++;
+ if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $row[$id], $row[$mail], $uf, 1, 'Individual', TRUE)) {
+ $contactCreated++;
+ }
+ else {
+ $contactMatching++;
+ }
+ if (is_object($match)) {
+ $match->free();
+ }
+ }
+
+ return array(
+ 'contactCount' => $contactCount,
+ 'contactMatching' => $contactMatching,
+ 'contactCreated' => $contactCreated,
+ );
+ }
+
}
$list[] = 'js/crm.joomla.js';
}
+ /**
+ * @inheritDoc
+ */
+ public function synchronizeUsers() {
+ $config = CRM_Core_Config::singleton();
+ if (PHP_SAPI != 'cli') {
+ set_time_limit(300);
+ }
+ $id = 'id';
+ $mail = 'email';
+ $name = 'name';
+
+ $JUserTable = &JTable::getInstance('User', 'JTable');
+
+ $db = $JUserTable->getDbo();
+ $query = $db->getQuery(TRUE);
+ $query->select($id . ', ' . $mail . ', ' . $name);
+ $query->from($JUserTable->getTableName());
+ $query->where($mail != '');
+
+ $db->setQuery($query);
+ $users = $db->loadObjectList();
+
+ $user = new StdClass();
+ $uf = $config->userFramework;
+ $contactCount = 0;
+ $contactCreated = 0;
+ $contactMatching = 0;
+ for ($i = 0; $i < count($users); $i++) {
+ $user->$id = $users[$i]->$id;
+ $user->$mail = $users[$i]->$mail;
+ $user->$name = $users[$i]->$name;
+ $contactCount++;
+ if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user,
+ $users[$i]->$id,
+ $users[$i]->$mail,
+ $uf,
+ 1,
+ 'Individual',
+ TRUE
+ )
+ ) {
+ $contactCreated++;
+ }
+ else {
+ $contactMatching++;
+ }
+ if (is_object($match)) {
+ $match->free();
+ }
+ }
+
+ return array(
+ 'contactCount' => $contactCount,
+ 'contactMatching' => $contactMatching,
+ 'contactCreated' => $contactCreated,
+ );
+ }
+
}
$list[] = 'js/crm.wordpress.js';
}
+ /**
+ * @inheritDoc
+ */
+ public function synchronizeUsers() {
+ $config = CRM_Core_Config::singleton();
+ if (PHP_SAPI != 'cli') {
+ set_time_limit(300);
+ }
+ $id = 'ID';
+ $mail = 'user_email';
+
+ $uf = $config->userFramework;
+ $contactCount = 0;
+ $contactCreated = 0;
+ $contactMatching = 0;
+
+ global $wpdb;
+ $wpUserIds = $wpdb->get_col("SELECT $wpdb->users.ID FROM $wpdb->users");
+
+ foreach ($wpUserIds as $wpUserId) {
+ $wpUserData = get_userdata($wpUserId);
+ $contactCount++;
+ if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($wpUserData,
+ $wpUserData->$id,
+ $wpUserData->$mail,
+ $uf,
+ 1,
+ 'Individual',
+ TRUE
+ )
+ ) {
+ $contactCreated++;
+ }
+ else {
+ $contactMatching++;
+ }
+ if (is_object($match)) {
+ $match->free();
+ }
+ }
+
+ return array(
+ 'contactCount' => $contactCount,
+ 'contactMatching' => $contactMatching,
+ 'contactCreated' => $contactCreated,
+ );
+ }
+
}