示例#1
0
 /**
  * @param array $cxn
  * @param string $entity
  * @param string $action
  * @param array $params
  * @return mixed
  */
 public static function route($cxn, $entity, $action, $params)
 {
     $SUPER_PERM = array('administer CiviCRM');
     require_once 'api/v3/utils.php';
     // FIXME: Shouldn't the X-Forwarded-Proto check be part of CRM_Utils_System::isSSL()?
     if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enableSSL') && !CRM_Utils_System::isSSL() && strtolower(CRM_Utils_Array::value('X_FORWARDED_PROTO', CRM_Utils_System::getRequestHeaders())) != 'https') {
         return civicrm_api3_create_error('System policy requires HTTPS.');
     }
     // Note: $cxn and cxnId are authenticated before router is called.
     $dao = new CRM_Cxn_DAO_Cxn();
     $dao->cxn_id = $cxn['cxnId'];
     if (empty($cxn['cxnId']) || !$dao->find(TRUE) || !$dao->cxn_id) {
         return civicrm_api3_create_error('Failed to lookup connection authorizations.');
     }
     if (!$dao->is_active) {
         return civicrm_api3_create_error('Connection is inactive.');
     }
     if (!is_string($entity) || !is_string($action) || !is_array($params)) {
         return civicrm_api3_create_error('API parameters are malformed.');
     }
     if (empty($cxn['perm']['api']) || !is_array($cxn['perm']['api']) || empty($cxn['perm']['grant']) || !(is_array($cxn['perm']['grant']) || is_string($cxn['perm']['grant']))) {
         return civicrm_api3_create_error('Connection has no permissions.');
     }
     $whitelist = \Civi\API\WhitelistRule::createAll($cxn['perm']['api']);
     \Civi::service('dispatcher')->addSubscriber(new \Civi\API\Subscriber\WhitelistSubscriber($whitelist));
     CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp();
     if ($cxn['perm']['grant'] === '*') {
         CRM_Core_Config::singleton()->userPermissionTemp->grant($SUPER_PERM);
     } else {
         CRM_Core_Config::singleton()->userPermissionTemp->grant($cxn['perm']['grant']);
     }
     $params['check_permissions'] = 'whitelist';
     return civicrm_api($entity, $action, $params);
 }
 /**
  * @inheritDoc
  */
 public function add($cxn)
 {
     $dao = new CRM_Cxn_DAO_Cxn();
     $dao->cxn_guid = $cxn['cxnId'];
     $dao->find(TRUE);
     $this->convertCxnToDao($cxn, $dao);
     $dao->save();
     $sql = '
   UPDATE civicrm_cxn SET created_date = modified_date
   WHERE created_date IS NULL
   AND cxn_guid = %1
   ';
     CRM_Core_DAO::executeQuery($sql, array(1 => array($cxn['cxnId'], 'String')));
     $this->cxns[$cxn['cxnId']] = $cxn;
 }
示例#3
0
/**
 * Adjust metadata for "getlink" action.
 *
 * @param array $spec
 *   List of fields.
 */
function _civicrm_api3_cxn_getlink_spec(&$spec)
{
    $daoFields = CRM_Cxn_DAO_Cxn::fields();
    $spec['app_guid'] = $daoFields['app_guid'];
    $spec['cxn_guid'] = $daoFields['cxn_guid'];
    $spec['page'] = array('name' => 'page', 'type' => CRM_Utils_Type::T_STRING, 'title' => ts('Page Type'), 'description' => 'The type of page (eg "settings")', 'maxlength' => 63, 'size' => CRM_Utils_Type::HUGE);
}
示例#4
0
/**
 * Creates or modifies a Cxn row.
 *
 * @param array $params
 *   Array with keys:
 *   - id, cxn_guid OR app_guid: string.
 *   - is_active: boolean.
 *   - options: JSON
 * @return page
 * @throws Exception
 */
function civicrm_api3_cxn_create($params)
{
    $result = "";
    try {
        // get the ID
        if (!empty($params['id'])) {
            $cxnId = $params['id'];
        } else {
            $cxnId = _civicrm_api3_cxn_parseCxnId($params);
        }
        // see if it's sth to update
        if (isset($params['options']) || isset($params['is_active'])) {
            $dao = new CRM_Cxn_DAO_Cxn();
            $dao->id = $cxnId;
            if ($dao->find()) {
                if (isset($params['is_active'])) {
                    $dao->is_active = (int) $params['is_active'];
                }
                if (isset($params['options'])) {
                    $dao->options = $params['options'];
                }
                $result = $dao->save();
            }
        }
        return civicrm_api3_create_success($result, $params, 'Cxn', 'create');
    } catch (Exception $ex) {
        throw $ex;
    }
}
示例#5
0
文件: Cxn.php 项目: agroknow/mermix
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['cxn'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }