当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Core_DAO::free方法代码示例

本文整理汇总了PHP中CRM_Core_DAO::free方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_DAO::free方法的具体用法?PHP CRM_Core_DAO::free怎么用?PHP CRM_Core_DAO::free使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Core_DAO的用法示例。


在下文中一共展示了CRM_Core_DAO::free方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: completeTransaction

 function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE)
 {
     $contribution =& $objects['contribution'];
     $primaryContributionID = isset($contribution->id) ? $contribution->id : $objects['first_contribution']->id;
     $memberships =& $objects['membership'];
     if (is_numeric($memberships)) {
         $memberships = array($objects['membership']);
     }
     $participant =& $objects['participant'];
     $event =& $objects['event'];
     $changeToday = CRM_Utils_Array::value('trxn_date', $input, self::$_now);
     $recurContrib =& $objects['contributionRecur'];
     $values = array();
     if (isset($input['is_email_receipt'])) {
         $values['is_email_receipt'] = $input['is_email_receipt'];
     }
     $source = NULL;
     if ($input['component'] == 'contribute') {
         if ($contribution->contribution_page_id) {
             CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
             $source = ts('Online Contribution') . ': ' . $values['title'];
         } elseif ($recurContrib && $recurContrib->id) {
             $contribution->contribution_page_id = NULL;
             $values['amount'] = $recurContrib->amount;
             $values['financial_type_id'] = $objects['contributionType']->id;
             $values['title'] = $source = ts('Offline Recurring Contribution');
             $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
             $values['receipt_from_name'] = $domainValues[0];
             $values['receipt_from_email'] = $domainValues[1];
         }
         if ($recurContrib && $recurContrib->id && !isset($input['is_email_receipt'])) {
             //CRM-13273 - is_email_receipt setting on recurring contribution should take precedence over contribution page setting
             // but CRM-16124 if $input['is_email_receipt'] is set then that should not be overridden.
             $values['is_email_receipt'] = $recurContrib->is_email_receipt;
         }
         $contribution->source = $source;
         if (CRM_Utils_Array::value('is_email_receipt', $values)) {
             $contribution->receipt_date = self::$_now;
         }
         if (!empty($memberships)) {
             $membershipsUpdate = array();
             foreach ($memberships as $membershipTypeIdKey => $membership) {
                 if ($membership) {
                     $format = '%Y%m%d';
                     $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id);
                     // CRM-8141 update the membership type with the value recorded in log when membership created/renewed
                     // this picks up membership type changes during renewals
                     $sql = "\nSELECT    membership_type_id\nFROM      civicrm_membership_log\nWHERE     membership_id={$membership->id}\nORDER BY  id DESC\nLIMIT 1;";
                     $dao = new CRM_Core_DAO();
                     $dao->query($sql);
                     if ($dao->fetch()) {
                         if (!empty($dao->membership_type_id)) {
                             $membership->membership_type_id = $dao->membership_type_id;
                             $membership->save();
                         }
                         // else fall back to using current membership type
                     }
                     // else fall back to using current membership type
                     $dao->free();
                     $num_terms = $contribution->getNumTermsByContributionAndMembershipType($membership->membership_type_id, $primaryContributionID);
                     if ($currentMembership) {
                         /*
                          * Fixed FOR CRM-4433
                          * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
                          * when Contribution mode is notify and membership is for renewal )
                          */
                         CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);
                         // @todo - we should pass membership_type_id instead of null here but not
                         // adding as not sure of testing
                         $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday, NULL, $num_terms);
                         $dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
                     } else {
                         $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id, NULL, NULL, NULL, $num_terms);
                     }
                     //get the status for membership.
                     $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE, $membership->membership_type_id, (array) $membership);
                     $formatedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, 2), 'join_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $dates), $format), 'start_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $dates), $format), 'end_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $dates), $format));
                     //we might be renewing membership,
                     //so make status override false.
                     $formatedParams['is_override'] = FALSE;
                     $membership->copyValues($formatedParams);
                     $membership->save();
                     //updating the membership log
                     $membershipLog = array();
                     $membershipLog = $formatedParams;
                     $logStartDate = $formatedParams['start_date'];
                     if (CRM_Utils_Array::value('log_start_date', $dates)) {
                         $logStartDate = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
                         $logStartDate = CRM_Utils_Date::isoToMysql($logStartDate);
                     }
                     $membershipLog['start_date'] = $logStartDate;
                     $membershipLog['membership_id'] = $membership->id;
                     $membershipLog['modified_id'] = $membership->contact_id;
                     $membershipLog['modified_date'] = date('Ymd');
                     $membershipLog['membership_type_id'] = $membership->membership_type_id;
                     CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
                     //update related Memberships.
                     CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams);
                     //update the membership type key of membership relatedObjects array
                     //if it has changed after membership update
//.........这里部分代码省略.........
开发者ID:TheCraftyCanvas,项目名称:aegir-platforms,代码行数:101,代码来源:BaseIPN.php

示例2: getZipCodeInfo

 /**
  * @return array
  */
 public function getZipCodeInfo()
 {
     if (!$this->stateMap) {
         $query = 'SELECT id, name, abbreviation from civicrm_state_province where country_id = 1228';
         $dao = new CRM_Core_DAO();
         $dao->query($query);
         $this->stateMap = array();
         while ($dao->fetch()) {
             $this->stateMap[$dao->abbreviation] = $dao->id;
             $this->states[$dao->id] = $dao->name;
         }
         $dao->free();
     }
     $offset = mt_rand(1, 43000);
     $query = "SELECT city, state, zip, latitude, longitude FROM zipcodes LIMIT {$offset}, 1";
     $dao = new CRM_Core_DAO();
     $dao->query($query);
     while ($dao->fetch()) {
         if ($this->stateMap[$dao->state]) {
             $stateID = $this->stateMap[$dao->state];
         } else {
             $stateID = 1004;
         }
         $zip = str_pad($dao->zip, 5, '0', STR_PAD_LEFT);
         return array(1228, $stateID, $dao->city, $zip, $dao->latitude, $dao->longitude);
     }
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:30,代码来源:GenerateData.php

示例3: completeTransaction

 function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE)
 {
     $contribution =& $objects['contribution'];
     $memberships =& $objects['membership'];
     if (is_numeric($memberships)) {
         $memberships = array($objects['membership']);
     }
     $participant =& $objects['participant'];
     $event =& $objects['event'];
     $changeToday = CRM_Utils_Array::value('trxn_date', $input, self::$_now);
     $recurContrib =& $objects['contributionRecur'];
     $values = array();
     if ($input['component'] == 'contribute') {
         if ($contribution->contribution_page_id) {
             CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
             $source = ts('Online Contribution') . ': ' . $values['title'];
         } elseif ($recurContrib->id) {
             $contribution->contribution_page_id = NULL;
             $values['amount'] = $recurContrib->amount;
             $values['contribution_type_id'] = $objects['contributionType']->id;
             $values['title'] = $source = ts('Offline Recurring Contribution');
             $values['is_email_receipt'] = $recurContrib->is_email_receipt;
             $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
             $values['receipt_from_name'] = $domainValues[0];
             $values['receipt_from_email'] = $domainValues[1];
         }
         $contribution->source = $source;
         if (CRM_Utils_Array::value('is_email_receipt', $values)) {
             $contribution->receipt_date = self::$_now;
         }
         if (!empty($memberships)) {
             foreach ($memberships as $membershipTypeIdKey => $membership) {
                 if ($membership) {
                     $format = '%Y%m%d';
                     $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id);
                     // CRM-8141 update the membership type with the value recorded in log when membership created/renewed
                     // this picks up membership type changes during renewals
                     $sql = "\nSELECT    membership_type_id\nFROM      civicrm_membership_log\nWHERE     membership_id={$membership->id}\nORDER BY  id DESC\nLIMIT 1;";
                     $dao = new CRM_Core_DAO();
                     $dao->query($sql);
                     if ($dao->fetch()) {
                         if (!empty($dao->membership_type_id)) {
                             $membership->membership_type_id = $dao->membership_type_id;
                             $membership->save();
                         }
                         // else fall back to using current membership type
                     }
                     // else fall back to using current membership type
                     $dao->free();
                     if ($currentMembership) {
                         /*
                          * Fixed FOR CRM-4433
                          * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
                          * when Contribution mode is notify and membership is for renewal )
                          */
                         CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);
                         $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday);
                         $dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
                     } else {
                         $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id);
                     }
                     //get the status for membership.
                     $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE);
                     $formatedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, 2), 'join_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $dates), $format), 'start_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $dates), $format), 'end_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $dates), $format), 'reminder_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('reminder_date', $dates), $format));
                     //we might be renewing membership,
                     //so make status override false.
                     $formatedParams['is_override'] = FALSE;
                     $membership->copyValues($formatedParams);
                     $membership->save();
                     //updating the membership log
                     $membershipLog = array();
                     $membershipLog = $formatedParams;
                     $logStartDate = $formatedParams['start_date'];
                     if (CRM_Utils_Array::value('log_start_date', $dates)) {
                         $logStartDate = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
                         $logStartDate = CRM_Utils_Date::isoToMysql($logStartDate);
                     }
                     $membershipLog['start_date'] = $logStartDate;
                     $membershipLog['membership_id'] = $membership->id;
                     $membershipLog['modified_id'] = $membership->contact_id;
                     $membershipLog['modified_date'] = date('Ymd');
                     $membershipLog['membership_type_id'] = $membership->membership_type_id;
                     CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
                     //update related Memberships.
                     CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams);
                     //update the membership type key of membership relatedObjects array
                     //if it has changed after membership update
                     if ($membershipTypeIdKey != $membership->membership_type_id) {
                         $memberships[$membership->membership_type_id] = $membership;
                         $contribution->_relatedObjects['membership'][$membership->membership_type_id] = $membership;
                         unset($contribution->_relatedObjects['membership'][$membershipTypeIdKey]);
                         unset($memberships[$membershipTypeIdKey]);
                     }
                 }
             }
         }
     } else {
         // event
         $eventParams = array('id' => $objects['event']->id);
         $values['event'] = array();
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:BaseIPN.php

示例4: testCreateSingleValueAlter

 /**
  * @dataProvider entities_updatesingle
  *
  * limitations include the problem with avoiding loops when creating test objects -
  * hence FKs only set by createTestObject when required. e.g parent_id on campaign is not being followed through
  * Currency - only seems to support US
  */
 public function testCreateSingleValueAlter($entityName)
 {
     if (in_array($entityName, $this->toBeImplemented['create'])) {
         // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
         return;
     }
     $baoString = _civicrm_api3_get_DAO($entityName);
     $this->assertNotEmpty($baoString, $entityName);
     $this->assertNotEmpty($entityName, $entityName);
     $fieldsget = $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'get'));
     if ($entityName != 'Pledge') {
         $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create'));
     }
     $fields = $fields['values'];
     $return = array_keys($fieldsget['values']);
     $valuesNotToReturn = $this->getKnownUnworkablesUpdateSingle($entityName, 'break_return');
     // these can't be requested as return values
     $entityValuesThatDontWork = array_merge($this->getKnownUnworkablesUpdateSingle($entityName, 'cant_update'), $this->getKnownUnworkablesUpdateSingle($entityName, 'cant_return'), $valuesNotToReturn);
     $return = array_diff($return, $valuesNotToReturn);
     $baoObj = new CRM_Core_DAO();
     $baoObj->createTestObject($baoString, array('currency' => 'USD'), 2, 0);
     $getentities = $this->callAPISuccess($entityName, 'get', array('sequential' => 1, 'return' => $return, 'options' => array('sort' => 'id DESC', 'limit' => 2)));
     // lets use first rather than assume only one exists
     $entity = $getentities['values'][0];
     $entity2 = $getentities['values'][1];
     foreach ($fields as $field => $specs) {
         $fieldName = $field;
         if (!empty($specs['uniquename'])) {
             $fieldName = $specs['uniquename'];
         }
         if ($field == 'currency' || $field == 'id' || $field == strtolower($entityName) . '_id' || in_array($field, $entityValuesThatDontWork)) {
             //@todo id & entity_id are correct but we should fix currency & frequency_day
             continue;
         }
         switch ($specs['type']) {
             case CRM_Utils_Type::T_DATE:
             case CRM_Utils_Type::T_TIMESTAMP:
                 $entity[$fieldName] = '2012-05-20';
                 break;
                 //case CRM_Utils_Type::T_DATETIME:
             //case CRM_Utils_Type::T_DATETIME:
             case 12:
                 $entity[$fieldName] = '2012-05-20 03:05:20';
                 break;
             case CRM_Utils_Type::T_STRING:
             case CRM_Utils_Type::T_BLOB:
             case CRM_Utils_Type::T_MEDIUMBLOB:
             case CRM_Utils_Type::T_TEXT:
             case CRM_Utils_Type::T_LONGTEXT:
             case CRM_Utils_Type::T_EMAIL:
                 $entity[$fieldName] = substr('New String', 0, CRM_Utils_Array::Value('maxlength', $specs, 100));
                 break;
             case CRM_Utils_Type::T_INT:
                 // probably created with a 1
                 $entity[$fieldName] = '6';
                 if (!empty($specs['FKClassName'])) {
                     if ($specs['FKClassName'] == $baoString) {
                         $entity[$fieldName] = (string) $entity2['id'];
                     } else {
                         $uniqueName = CRM_Utils_Array::value('uniqueName', $specs);
                         $entity[$fieldName] = (string) empty($entity2[$field]) ? CRM_Utils_Array::value($uniqueName, $entity2) : $entity2[$field];
                         //todo - there isn't always something set here - & our checking on unset values is limited
                         if (empty($entity[$field])) {
                             unset($entity[$field]);
                         }
                     }
                 }
                 break;
             case CRM_Utils_Type::T_BOOLEAN:
                 // probably created with a 1
                 $entity[$fieldName] = '0';
                 break;
             case CRM_Utils_Type::T_FLOAT:
             case CRM_Utils_Type::T_MONEY:
                 $entity[$field] = '222';
                 break;
             case CRM_Utils_Type::T_URL:
                 $entity[$field] = 'warm.beer.com';
         }
         if (!empty($specs['pseudoconstant']) || !empty($specs['enumValues'])) {
             $options = $this->callAPISuccess($entityName, 'getoptions', array('context' => 'create', 'field' => $field));
             if (empty($options['values'])) {
             }
             $entity[$field] = array_rand($options['values']);
         }
         $updateParams = array('id' => $entity['id'], $field => isset($entity[$field]) ? $entity[$field] : NULL);
         $update = $this->callAPISuccess($entityName, 'create', $updateParams);
         $checkParams = array('id' => $entity['id'], 'sequential' => 1, 'return' => $return, 'options' => array('sort' => 'id DESC', 'limit' => 2));
         $checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams);
         $this->assertAPIArrayComparison($entity, $checkEntity, array(), "checking if {$fieldName} was correctly updaetd\n" . print_r(array('update-params' => $updateParams, 'update-result' => $update, 'getsingle-params' => $checkParams, 'getsingle-result' => $checkEntity, 'expected entity' => $entity), TRUE));
     }
     $baoObj->deleteTestObjects($baoString);
     $baoObj->free();
//.........这里部分代码省略.........
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:101,代码来源:SyntaxConformanceTest.php

示例5: transitionComponents


//.........这里部分代码省略.........
             CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID, $pledgePaymentIDs, $contributionStatusId);
             $updateResult['updatedComponents']['CiviPledge'] = $contributionStatusId;
             if ($processContributionObject) {
                 $processContribution = TRUE;
             }
         }
     } elseif ($contributionStatusId == array_search('Completed', $contributionStatuses)) {
         // only pending contribution related object processed.
         if ($previousContriStatusId && $previousContriStatusId != array_search('Pending', $contributionStatuses)) {
             // this is case when we already processed contribution object.
             return $updateResult;
         } elseif (!$previousContriStatusId && $contribution->contribution_status_id != array_search('Pending', $contributionStatuses)) {
             // this is case when we are going to process contribution object later.
             return $updateResult;
         }
         if (is_array($memberships)) {
             foreach ($memberships as $membership) {
                 if ($membership) {
                     $format = '%Y%m%d';
                     //CRM-4523
                     $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id);
                     // CRM-8141 update the membership type with the value recorded in log when membership created/renewed
                     // this picks up membership type changes during renewals
                     $sql = "\n              SELECT    membership_type_id\n              FROM      civicrm_membership_log\n              WHERE     membership_id={$membership->id}\n              ORDER BY  id DESC\n              LIMIT     1;";
                     $dao = new CRM_Core_DAO();
                     $dao->query($sql);
                     if ($dao->fetch()) {
                         if (!empty($dao->membership_type_id)) {
                             $membership->membership_type_id = $dao->membership_type_id;
                             $membership->save();
                         }
                     }
                     // else fall back to using current membership type
                     $dao->free();
                     // Figure out number of terms
                     $numterms = 1;
                     $lineitems = CRM_Price_BAO_LineItem::getLineItems($contributionId, 'contribution');
                     foreach ($lineitems as $lineitem) {
                         if ($membership->membership_type_id == CRM_Utils_Array::value('membership_type_id', $lineitem)) {
                             $numterms = CRM_Utils_Array::value('membership_num_terms', $lineitem);
                             // in case membership_num_terms comes through as null or zero
                             $numterms = $numterms >= 1 ? $numterms : 1;
                             break;
                         }
                     }
                     // CRM-15735-to update the membership status as per the contribution receive date
                     $joinDate = NULL;
                     if (!empty($params['receive_date'])) {
                         $joinDate = $params['receive_date'];
                         $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($membership->start_date, $membership->end_date, $membership->join_date, $params['receive_date'], FALSE, $membership->membership_type_id, (array) $membership);
                         $membership->status_id = CRM_Utils_Array::value('id', $status, $membership->status_id);
                         $membership->save();
                     }
                     if ($currentMembership) {
                         CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, NULL);
                         $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, NULL, NULL, $numterms);
                         $dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
                     } else {
                         $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id, $joinDate, NULL, NULL, $numterms);
                     }
                     //get the status for membership.
                     $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE, $membership->membership_type_id, (array) $membership);
                     $formattedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, array_search('Current', $membershipStatuses)), 'join_date' => CRM_Utils_Date::customFormat($dates['join_date'], $format), 'start_date' => CRM_Utils_Date::customFormat($dates['start_date'], $format), 'end_date' => CRM_Utils_Date::customFormat($dates['end_date'], $format));
                     CRM_Utils_Hook::pre('edit', 'Membership', $membership->id, $formattedParams);
                     $membership->copyValues($formattedParams);
                     $membership->save();
开发者ID:nganivet,项目名称:civicrm-core,代码行数:67,代码来源:Contribution.php

示例6: array

 /**
  * Execute a query and get the single result.
  *
  * @param string $query
  *   Query to be executed.
  * @param array $params
  * @param bool $abort
  * @param bool $i18nRewrite
  * @return string|null
  *   the result of the query if any
  *
  */
 public static function &singleValueQuery($query, $params = array(), $abort = TRUE, $i18nRewrite = TRUE)
 {
     $queryStr = self::composeQuery($query, $params, $abort);
     static $_dao = NULL;
     if (!$_dao) {
         $_dao = new CRM_Core_DAO();
     }
     $_dao->query($queryStr, $i18nRewrite);
     $result = $_dao->getDatabaseResult();
     $ret = NULL;
     if ($result) {
         $row = $result->fetchRow();
         if ($row) {
             $ret = $row[0];
         }
     }
     $_dao->free();
     return $ret;
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:31,代码来源:DAO.php

示例7: fillTable

 public function fillTable()
 {
     // get the list of queries handy
     $tableQueries = $this->tableQuery();
     if ($this->params && !$this->noRules) {
         $tempTableQuery = "CREATE TEMPORARY TABLE dedupe (id1 int, weight int, UNIQUE UI_id1 (id1)) ENGINE=MyISAM";
         $insertClause = "INSERT INTO dedupe (id1, weight)";
         $groupByClause = "GROUP BY id1";
         $dupeCopyJoin = " JOIN dedupe_copy ON dedupe_copy.id1 = t1.column WHERE ";
     } else {
         $tempTableQuery = "CREATE TEMPORARY TABLE dedupe (id1 int, id2 int, weight int, UNIQUE UI_id1_id2 (id1, id2)) ENGINE=MyISAM";
         $insertClause = "INSERT INTO dedupe (id1, id2, weight)";
         $groupByClause = "GROUP BY id1, id2";
         $dupeCopyJoin = " JOIN dedupe_copy ON dedupe_copy.id1 = t1.column AND dedupe_copy.id2 = t2.column WHERE ";
     }
     $patternColumn = '/t1.(\\w+)/';
     $exclWeightSum = array();
     // create temp table
     $dao = new CRM_Core_DAO();
     $dao->query($tempTableQuery);
     CRM_Utils_Hook::dupeQuery($this, 'table', $tableQueries);
     while (!empty($tableQueries)) {
         list($isInclusive, $isDie) = self::isQuerySetInclusive($tableQueries, $this->threshold, $exclWeightSum);
         if ($isInclusive) {
             // order queries by table count
             self::orderByTableCount($tableQueries);
             $weightSum = array_sum($exclWeightSum);
             $searchWithinDupes = !empty($exclWeightSum) ? 1 : 0;
             while (!empty($tableQueries)) {
                 // extract the next query ( and weight ) to be executed
                 $fieldWeight = array_keys($tableQueries);
                 $fieldWeight = $fieldWeight[0];
                 $query = array_shift($tableQueries);
                 if ($searchWithinDupes) {
                     // get prepared to search within already found dupes if $searchWithinDupes flag is set
                     $dao->query("DROP TEMPORARY TABLE IF EXISTS dedupe_copy");
                     $dao->query("CREATE TEMPORARY TABLE dedupe_copy SELECT * FROM dedupe WHERE weight >= {$weightSum}");
                     $dao->free();
                     preg_match($patternColumn, $query, $matches);
                     $query = str_replace(' WHERE ', str_replace('column', $matches[1], $dupeCopyJoin), $query);
                 }
                 $searchWithinDupes = 1;
                 // construct and execute the intermediate query
                 $query = "{$insertClause} {$query} {$groupByClause} ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight)";
                 $dao->query($query);
                 // FIXME: we need to be more acurate with affected rows, especially for insert vs duplicate insert.
                 // And that will help optimize further.
                 $affectedRows = $dao->affectedRows();
                 $dao->free();
                 // In an inclusive situation, failure of any query means no further processing -
                 if ($affectedRows == 0) {
                     // reset to make sure no further execution is done.
                     $tableQueries = array();
                     break;
                 }
                 $weightSum = substr($fieldWeight, strrpos($fieldWeight, '.') + 1) + $weightSum;
             }
             // An exclusive situation -
         } elseif (!$isDie) {
             // since queries are already sorted by weights, we can continue as is
             $fieldWeight = array_keys($tableQueries);
             $fieldWeight = $fieldWeight[0];
             $query = array_shift($tableQueries);
             $query = "{$insertClause} {$query} {$groupByClause} ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight)";
             $dao->query($query);
             if ($dao->affectedRows() >= 1) {
                 $exclWeightSum[] = substr($fieldWeight, strrpos($fieldWeight, '.') + 1);
             }
             $dao->free();
         } else {
             // its a die situation
             break;
         }
     }
 }
开发者ID:saurabhbatra96,项目名称:civicrm-core,代码行数:75,代码来源:RuleGroup.php

示例8: run


//.........这里部分代码省略.........
         }
         // Ignore the "options" param if it is referring to api options and not a field in this entity
         if ($key === 'options' && is_array($value) && !in_array(\CRM_Utils_Array::first(array_keys($value)), \CRM_Core_DAO::acceptedSQLOperators())) {
             continue;
         }
         $field = $this->getField($key);
         if ($field) {
             $key = $field['name'];
         }
         if (in_array($key, $this->entityFieldNames)) {
             $table_name = 'a';
             $column_name = $key;
         } elseif (($cf_id = \CRM_Core_BAO_CustomField::getKeyID($key)) != FALSE) {
             list($table_name, $column_name) = $this->addCustomField($custom_fields[$cf_id]);
         } elseif (strpos($key, '.')) {
             $fkInfo = $this->addFkField($key);
             if ($fkInfo) {
                 list($table_name, $column_name) = $fkInfo;
                 $this->validateNestedInput($key, $value);
             }
         }
         // I don't know why I had to specifically exclude 0 as a key - wouldn't the others have caught it?
         // We normally silently ignore null values passed in - if people want IS_NULL they can use acceptedSqlOperator syntax.
         if (!$table_name || empty($key) || is_null($value)) {
             // No valid filter field. This might be a chained call or something.
             // Just ignore this for the $where_clause.
             continue;
         }
         if (!is_array($value)) {
             $this->query->where(array("`{$table_name}`.`{$column_name}` = @value"), array("@value" => $value));
         } else {
             // We expect only one element in the array, of the form
             // "operator" => "rhs".
             $operator = \CRM_Utils_Array::first(array_keys($value));
             if (!in_array($operator, \CRM_Core_DAO::acceptedSQLOperators())) {
                 $this->query->where(array("{$table_name}.{$column_name} = @value"), array("@value" => $value));
             } else {
                 $this->query->where(\CRM_Core_DAO::createSQLFilter("{$table_name}.{$column_name}", $value));
             }
         }
     }
     if (!$this->options['is_count']) {
         foreach ($select_fields as $column => $alias) {
             $this->query->select("{$column} as `{$alias}`");
         }
     } else {
         $this->query->select("count(*) as c");
     }
     // order by
     if (!empty($this->options['sort'])) {
         $sort_fields = array();
         foreach (explode(',', $this->options['sort']) as $sort_option) {
             $words = preg_split("/[\\s]+/", $sort_option);
             if (count($words) > 0 && in_array($words[0], array_values($select_fields))) {
                 $tmp = $words[0];
                 if (!empty($words[1]) && strtoupper($words[1]) == 'DESC') {
                     $tmp .= " DESC";
                 }
                 $sort_fields[] = $tmp;
             }
         }
         if (count($sort_fields) > 0) {
             $this->query->orderBy(implode(",", $sort_fields));
         }
     }
     // limit
     if (!empty($this->options['limit']) || !empty($this->options['offset'])) {
         $this->query->limit($this->options['limit'], $this->options['offset']);
     }
     // ACLs
     $this->query->where($this->getAclClause('a'));
     $this->bao->free();
     $result_entities = array();
     $result_dao = \CRM_Core_DAO::executeQuery($this->query->toSQL());
     while ($result_dao->fetch()) {
         if ($this->options['is_count']) {
             $result_dao->free();
             return (int) $result_dao->c;
         }
         $result_entities[$result_dao->id] = array();
         foreach ($select_fields as $column => $alias) {
             $returnName = $alias;
             $alias = str_replace('.', '_', $alias);
             if (property_exists($result_dao, $alias) && $result_dao->{$alias} != NULL) {
                 $result_entities[$result_dao->id][$returnName] = $result_dao->{$alias};
             }
             // Backward compatibility on fields names.
             if ($this->isFillUniqueFields && !empty($this->apiFieldSpec[$alias]['uniqueName'])) {
                 $result_entities[$result_dao->id][$this->apiFieldSpec[$alias]['uniqueName']] = $result_dao->{$alias};
             }
             foreach ($this->apiFieldSpec as $returnName => $spec) {
                 if (empty($result_entities[$result_dao->id][$returnName]) && !empty($result_entities[$result_dao->id][$spec['name']])) {
                     $result_entities[$result_dao->id][$returnName] = $result_entities[$result_dao->id][$spec['name']];
                 }
             }
         }
     }
     $result_dao->free();
     return $result_entities;
 }
开发者ID:Prem-Patel,项目名称:civicrm-core,代码行数:101,代码来源:SelectQuery.php

示例9: testCreateSingleValueAlter


//.........这里部分代码省略.........
             case CRM_Utils_Type::T_STRING:
             case CRM_Utils_Type::T_BLOB:
             case CRM_Utils_Type::T_MEDIUMBLOB:
             case CRM_Utils_Type::T_TEXT:
             case CRM_Utils_Type::T_LONGTEXT:
             case CRM_Utils_Type::T_EMAIL:
                 if ($fieldName == 'form_values' && $entityName == 'SavedSearch') {
                     // This is a hack for the SavedSearch API.
                     // It expects form_values to be an array.
                     // If you want to fix this, you should definitely read this forum
                     // post.
                     // http://forum.civicrm.org/index.php/topic,33990.0.html
                     // See also my question on the CiviCRM Stack Exchange:
                     // https://civicrm.stackexchange.com/questions/3437
                     $entity[$fieldName] = array('sort_name' => "SortName2");
                 } else {
                     $entity[$fieldName] = substr('New String', 0, CRM_Utils_Array::Value('maxlength', $specs, 100));
                     // typecast with array to satisfy changes made in CRM-13160
                     if ($entityName == 'MembershipType' && in_array($fieldName, array('relationship_type_id', 'relationship_direction'))) {
                         $entity[$fieldName] = (array) $entity[$fieldName];
                     }
                 }
                 break;
             case CRM_Utils_Type::T_INT:
                 // probably created with a 1
                 if ($fieldName == 'weight') {
                     $entity[$fieldName] = 2;
                 } elseif (!empty($specs['FKClassName'])) {
                     if ($specs['FKClassName'] == $baoString) {
                         $entity[$fieldName] = (string) $entity2['id'];
                     } else {
                         $uniqueName = CRM_Utils_Array::value('uniqueName', $specs, $fieldName);
                         if (!empty($entity[$fieldName])) {
                             $resetFKTo = array($fieldName => $entity[$fieldName], $uniqueName => $entity[$fieldName]);
                         }
                         $entity[$fieldName] = (string) empty($entity2[$field]) ? CRM_Utils_Array::value($uniqueName, $entity2) : $entity2[$field];
                         //todo - there isn't always something set here - & our checking on unset values is limited
                         if (empty($entity[$field])) {
                             unset($entity[$field]);
                         }
                     }
                 } else {
                     $entity[$fieldName] = '6';
                 }
                 break;
             case CRM_Utils_Type::T_BOOLEAN:
                 // probably created with a 1
                 $entity[$fieldName] = '0';
                 break;
             case CRM_Utils_Type::T_FLOAT:
             case CRM_Utils_Type::T_MONEY:
                 $entity[$field] = '22.75';
                 break;
             case CRM_Utils_Type::T_URL:
                 $entity[$field] = 'warm.beer.com';
         }
         if (empty($specs['FKClassName']) && (!empty($specs['pseudoconstant']) || !empty($specs['options']))) {
             $options = CRM_Utils_Array::value('options', $specs, array());
             if (!$options) {
                 //eg. pdf_format id doesn't ship with any
                 if (isset($specs['pseudoconstant']['optionGroupName'])) {
                     $optionValue = $this->callAPISuccess('option_value', 'create', array('option_group_id' => $specs['pseudoconstant']['optionGroupName'], 'label' => 'new option value', 'sequential' => 1));
                     $optionValue = $optionValue['values'];
                     $keyColumn = CRM_Utils_Array::value('keyColumn', $specs['pseudoconstant'], 'value');
                     $options[$optionValue[0][$keyColumn]] = 'new option value';
                 }
             }
             $entity[$field] = array_rand($options);
         }
         if (!empty($specs['FKClassName']) && !empty($specs['pseudoconstant'])) {
             // in the weird situation where a field has both an fk and pseudoconstant defined,
             // e.g. campaign_id field, need to flush caches.
             // FIXME: Why doesn't creating a campaign clear caches?
             civicrm_api3($entityName, 'getfields', array('cache_clear' => 1));
         }
         $updateParams = array('id' => $entity['id'], $field => isset($entity[$field]) ? $entity[$field] : NULL);
         if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
             //api has special handling on these 2 fields for backward compatibility reasons
             $entity['contribution_type_id'] = $updateParams['financial_type_id'];
         }
         if (!empty($specs['uniqueName'])) {
             $entity[$specs['uniqueName']] = $entity[$specs['name']];
         }
         $update = $this->callAPISuccess($entityName, 'create', $updateParams);
         $checkParams = array('id' => $entity['id'], 'sequential' => 1, 'return' => $return, 'options' => array('sort' => 'id DESC', 'limit' => 2));
         $checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams);
         $this->assertAPIArrayComparison($entity, $checkEntity, array(), "checking if {$fieldName} was correctly updated\n" . print_r(array('update-params' => $updateParams, 'update-result' => $update, 'getsingle-params' => $checkParams, 'getsingle-result' => $checkEntity, 'expected entity' => $entity), TRUE));
         if ($resetFKTo) {
             //reset the foreign key fields because otherwise our cleanup routine fails & some other unexpected stuff can kick in
             $entity = array_merge($entity, $resetFKTo);
             $updateParams = array_merge($updateParams, $resetFKTo);
             $this->callAPISuccess($entityName, 'create', $updateParams);
             if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
                 //api has special handling on these 2 fields for backward compatibility reasons
                 $entity['contribution_type_id'] = $updateParams['financial_type_id'];
             }
         }
     }
     $baoObj->free();
 }
开发者ID:rollox,项目名称:civicrm-core,代码行数:101,代码来源:SyntaxConformanceTest.php

示例10: releaseItem

 /**
  * Return an item that could not be processed.
  *
  * @param CRM_Core_DAO $dao
  *   The item returned by claimItem.
  */
 public function releaseItem($dao)
 {
     $sql = "UPDATE civicrm_queue_item SET release_time = NULL WHERE id = %1";
     $params = array(1 => array($dao->id, 'Integer'));
     CRM_Core_DAO::executeQuery($sql, $params);
     $dao->free();
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:13,代码来源:Sql.php

示例11: testCreateAutoGrant

 /**
  * This is a test to check if setting fields one at a time alters other fields.
  *
  * Issues Hit so far =
  * 1) Currency keeps getting reset to USD -  BUT this may be the only enabled currency
  *  - in which case it is valid
  * 2)
  */
 public function testCreateAutoGrant()
 {
     $entityName = $this->_entity;
     $baoString = 'CRM_Grant_BAO_Grant';
     $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create'));
     $fields = $fields['values'];
     $return = array_keys($fields);
     $baoObj = new CRM_Core_DAO();
     $baoObj->createTestObject($baoString, array('currency' => 'USD'), 2, 0);
     $getentities = $this->callAPISuccess($entityName, 'get', array('sequential' => 1, 'return' => $return));
     // lets use first rather than assume only one exists
     $entity = $getentities['values'][0];
     $entity2 = $getentities['values'][1];
     foreach ($fields as $field => $specs) {
         if ($field == 'currency' || $field == 'id') {
             continue;
         }
         switch ($specs['type']) {
             case CRM_Utils_Type::T_DATE:
             case CRM_Utils_Type::T_TIMESTAMP:
                 $entity[$field] = '2012-05-20';
                 break;
             case CRM_Utils_Type::T_STRING:
             case CRM_Utils_Type::T_BLOB:
             case CRM_Utils_Type::T_MEDIUMBLOB:
             case CRM_Utils_Type::T_TEXT:
             case CRM_Utils_Type::T_LONGTEXT:
             case CRM_Utils_Type::T_EMAIL:
                 $entity[$field] = 'New String';
                 break;
             case CRM_Utils_Type::T_INT:
                 // probably created with a 1
                 $entity[$field] = 2;
                 if (!empty($specs['FKClassName'])) {
                     $entity[$field] = empty($entity2[$field]) ? $entity2[$specs]['uniqueName'] : $entity2[$field];
                 }
                 break;
             case CRM_Utils_Type::T_BOOLEAN:
                 // probably created with a 1
                 $entity[$field] = 0;
                 break;
             case CRM_Utils_Type::T_FLOAT:
             case CRM_Utils_Type::T_MONEY:
                 $entity[$field] = 222;
                 break;
             case CRM_Utils_Type::T_URL:
                 $entity[$field] = 'warm.beer.com';
         }
         $updateParams = array('id' => $entity['id'], $field => $entity[$field], 'debug' => 1);
         $update = $this->callAPISuccess($entityName, 'create', $updateParams);
         $this->assertAPISuccess($update, "setting {$field} to {$entity[$field]} in line " . __LINE__);
         $checkParams = array('id' => $entity['id'], 'sequential' => 1);
         $checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams);
         $this->assertAPIArrayComparison((array) $entity, $checkEntity);
     }
     $baoObj->deleteTestObjects($baoString);
     $baoObj->free();
 }
开发者ID:rajeshrhino,项目名称:civicrm-core,代码行数:66,代码来源:GrantTest.php

示例12: runSqlReturnAffectedRows

 /**
  * There's probably a better way to do this.
  */
 public static function runSqlReturnAffectedRows($sql, $params = array())
 {
     $dao = new CRM_Core_DAO();
     $q = CRM_Core_DAO::composeQuery($sql, $params);
     $result = $dao->query($q);
     if (is_a($result, 'DB_Error')) {
         throw new Exception($result->message . "\n" . $result->userinfo);
     }
     $dao->free();
     return $result;
 }
开发者ID:sunilpawar,项目名称:uk.co.vedaconsulting.mailchimp,代码行数:14,代码来源:Sync.php


注:本文中的CRM_Core_DAO::free方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。