Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-9135

Event create from template is using template values for created_date, created_id (causes permission error)

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.0.7
    • Fix Version/s: 4.1.0
    • Component/s: CiviEvent
    • Labels:
      None

      Description

      When an event is created the template fields are being used as defaults. This is causing 'created_id' & 'created_date' not to be set correctly (which means people can't edit the events they created).

      Index: CRM/Event/Form/ManageEvent/EventInfo.php
      ===================================================================
      — CRM/Event/Form/ManageEvent/EventInfo.php (revision 36620)
      +++ CRM/Event/Form/ManageEvent/EventInfo.php (working copy)
      @@ -317,19 +317,13 @@
      $this->_id,
      'Event' );

      • require_once 'CRM/Event/BAO/Event.php';
        +

      // copy all not explicitely set $params keys from the template (if it should be sourced)
      + // NB it would make sense to move this to the create function so
      + // api can also benefit from it
      if ( CRM_Utils_Array::value( 'template_id', $params ) ) {

      • $defaults = array();
      • $templateParams = array('id' => $params['template_id']);
      • CRM_Event_BAO_Event::retrieve($templateParams, $defaults);
      • unset($defaults['id']);
      • unset($defaults['default_fee_id']);
      • unset($defaults['default_discount_fee_id']);
      • foreach ($defaults as $key => $value) { - if (!isset($params[$key])) $params[$key] = $value; - }

        + $params = array_merge($this->getTemplateDefaultValues($params['template_id'],$params));
        }

      if ( empty( $params['is_template'] ) )

      { @@ -452,5 +446,33 @@ return $defaults; }

      + /*
      + * Retrieve event template default values to be set
      + * as default values for current new event.
      + *
      + * @params int $templateId event template id.
      + *
      + * @return $defaults an array of custom data defaults.
      + */
      + public function getTemplateDefaultValues( $templateId )
      + {
      + $defaults = array( );
      + if ( !$templateId )

      { + return $defaults; + }

      +
      + $templateParams = array('id' => $templateId);
      + require_once 'CRM/Event/BAO/Event.php';
      + CRM_Event_BAO_Event::retrieve($templateParams, $defaults);
      + $fieldsToExclude = array('id',
      + 'default_fee_id',
      + 'default_discount_fee_id',
      + 'created_date',
      + 'created_id',
      + 'is_template',
      + ) ;
      + $defaults = array_diff_key($defaults,array_flip($fieldsToExclude));
      + return $defaults;
      + }
      }

        Attachments

          Activity

            People

            • Assignee:
              eileen Eileen McNaughton
              Reporter:
              eileen Eileen McNaughton
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: