CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How to submit a patch for CRM\CORE\DAO.php
Pages: [1]

Author Topic: How to submit a patch for CRM\CORE\DAO.php  (Read 1839 times)

geeffland

  • I’m new here
  • *
  • Posts: 29
  • Karma: 0
How to submit a patch for CRM\CORE\DAO.php
May 14, 2010, 05:58:48 pm
I have tweaked the DAO.php file copyGeneric function to add a 'replace' functionality to complement the already implemented 'prefix' and 'suffix' functions.

For my use case I am using it to Copy Events and then 'replace' the start_date and end_date to get a copied event for a duplicate occurrence of an event.

Assuming the devs would like this enhancement (rather simple one), how do I submit a change?  Upload a patch (diff) file? Upload a full file that allows the devs to do their own diff? or other?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How to submit a patch for CRM\CORE\DAO.php
May 14, 2010, 06:40:46 pm

hey greg:

can you post the patch here, so we can check and figure out what you are referring to. thanx for offering to share your changes

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

geeffland

  • I’m new here
  • *
  • Posts: 29
  • Karma: 0
Re: How to submit a patch for CRM\CORE\DAO.php
May 16, 2010, 07:56:59 am
Was not sure how readable the "patch" was here so I decided to past the patch and the whole copyGeneric function.  The first three parts are to add the 'replace' functionality.  The last item is to fix something with dates.  The original code referenced the old object before applying prefix, suffix, or replace.

PATCH file from WinMerge
Code: [Select]
1026d1025
<                 $fieldsToReplace = array( ); //GE Added 4-7-2010
1034,1037d1032
<             // fieldsToReplace -- GE Added 4-7-2010
<             if ($fieldsFix['replace']) {
<                 $fieldsToReplace = $fieldsFix['replace'];
<             }
1053,1056d1047
<                 // fieldsToReplace -- GE Added 4-7-2010
<                 if ( isset( $fieldsToReplace[$dbName] ) ) {
<                     $newObject->$dbName = $fieldsToReplace[$dbName];
<                 }
1059,1060c1050
<                     //$newObject->$dbName = CRM_Utils_Date::isoToMysql($object->$dbName);
<                     $newObject->$dbName = CRM_Utils_Date::isoToMysql($newObject->$dbName); //GE Fixed this to ref newObject
---
>                     $newObject->$dbName = CRM_Utils_Date::isoToMysql($object->$dbName);

Whole Function:
Code: [Select]
    static function &copyGeneric( $daoName, $criteria , $newData = null, $fieldsFix = null, $blockCopyOfDependencies = null )
    {
        require_once(str_replace('_', DIRECTORY_SEPARATOR, $daoName) . ".php");
        eval( '$object   =& new ' . $daoName . '( );' );
        if ( ! $newData ) {
            $object->id =  $criteria['id'];     
        } else {
            foreach( $criteria as $key => $value ) {
                $object->$key = $value;
            }
        }

        $object->find( );
        while ( $object->fetch( ) ) {

            // all the objects except with $blockCopyOfDependencies set
            // be copied - addresses #CRM-1962

            if ( $blockCopyOfDependencies && $object->$blockCopyOfDependencies ) {
                break;
            }
           
            eval( '$newObject   =& new ' . $daoName . '( );' );
           
            $fields =& $object->fields( );
            if ( ! is_array( $fieldsFix ) ) {
                $fieldsToPrefix = array( );
                $fieldsToSuffix = array( );
                $fieldsToReplace = array( ); //GE Added 4-7-2010
            }
            if ($fieldsFix['prefix']) {
                $fieldsToPrefix = $fieldsFix['prefix'];
            }
            if ($fieldsFix['suffix']) {
                $fieldsToSuffix = $fieldsFix['suffix'];
            }
            // fieldsToReplace -- GE Added 4-7-2010
            if ($fieldsFix['replace']) {
                $fieldsToReplace = $fieldsFix['replace'];
            }

            foreach ( $fields as $name => $value ) {
                if ( $name == 'id' ) {
                    // copy everything but the id!
                    continue;
                }
               
                $dbName = $value['name'];
                $newObject->$dbName = $object->$dbName;
                if ( isset( $fieldsToPrefix[$dbName] ) ) {
                    $newObject->$dbName = $fieldsToPrefix[$dbName] . $newObject->$dbName;
                }
                if ( isset( $fieldsToSuffix[$dbName] ) ) {
                    $newObject->$dbName .= $fieldsToSuffix[$dbName];
                }
                // fieldsToReplace -- GE Added 4-7-2010
                if ( isset( $fieldsToReplace[$dbName] ) ) {
                    $newObject->$dbName = $fieldsToReplace[$dbName];
                }
               
                if( substr($name , -5) == '_date') {
                    //$newObject->$dbName = CRM_Utils_Date::isoToMysql($object->$dbName);
                    $newObject->$dbName = CRM_Utils_Date::isoToMysql($newObject->$dbName); //GE Fixed this to ref newObject
                }
               
                if ( $newData ) {
                    foreach( $newData as $k => $v ) {
                        $newObject->$k = $v;
                    }
                }
            }
            $newObject->save( );       
        }
        return $newObject;
    }

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How to submit a patch for CRM\CORE\DAO.php
May 16, 2010, 08:28:11 pm

hey greg:

can you file an issue (http://issues.civicrm.org/) and attach the patch to the issue. we'll patch the file in 3.2

also might make it easier to combine the modifications in 1053-1056 and 1059 under the same condition. i.e. change the data if needed before setting $newObject->$dbName

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

geeffland

  • I’m new here
  • *
  • Posts: 29
  • Karma: 0
Re: How to submit a patch for CRM\CORE\DAO.php
May 17, 2010, 07:30:46 am
Not sure I completely understand your comment about combining some of the code...  The replace function was added to be available for any field just like the prefix/suffix functions.  Then the date portion was fixed to reference the $newObject because as it was written prefix, suffix, or my new replace would not affect any date fields because it referenced the original $object (i.e. before any prefix, suffix, or replace method)

Thanks for the info!  I will file an issue with the patch.  should I file just the patch? whole function? whole file? similar to this post?

Greg

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How to submit a patch for CRM\CORE\DAO.php
May 17, 2010, 08:05:10 am

just the patch please

i think combining the code as follows is a wee bit better

Code: [Select]
                // fieldsToReplace -- GE Added 4-7-2010
                if ( isset( $fieldsToReplace[$dbName] ) ) {
                    if( substr($name , -5) == '_date') {
                         $newObject->$dbName = CRM_Utils_Date::isoToMysql( $fieldsToReplace[$dbName] );
                    } else {
                         $newObject->$dbName = $fieldsToReplace[$dbName];
                    }
                }
 
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

geeffland

  • I’m new here
  • *
  • Posts: 29
  • Karma: 0
Re: How to submit a patch for CRM\CORE\DAO.php
May 17, 2010, 09:03:52 am
I agree as long as it is intended that the date fields are not to be affected by 'prefix' or 'suffix' actions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • How to submit a patch for CRM\CORE\DAO.php

This forum was archived on 2017-11-26.