HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Database trigger in OCP

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#46297 (In Topic #10114)
Avatar

Fan in training

Hi,

I am developing a web application and integrating it with OCPortal. I am using the user profiles of OCPortal to store the information about the users. Added some custom profile fields. But when a user updates the profile, i don't want to lose the old data. So i am trying to save it into another table.

I managed to create a database trigger (UPDATE trigger… FOR EACH ROW ) on ocp4_f_member……. table. But the problem now is, if the user updates one custom profile field, the trigger is triggered 42 times ( looks like this is the number of my custom fields). SO there are 42 identical rows getting added to my olddata table. Whereas i want only only one row with the old data.

Is the OCPortal updating each field in the table seperately rather than as a row at a shot? How do i overcome this problem?

thanks,

Madhavi.
Back to the top
 
Posted
Rating:
#46299
Avatar

Looks like it is doing lots of updates. I'll see if we can resolve this, as obviously that's not optimal.
I'll get back to you soon.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#46300
Avatar

Here's a new sources/ocf_members_action.php compatible with 4.1.3 (and possibly earlier releases).
Attachment
» Download: ocf_members_action.php (62 Kb, 123 downloads so far)


Alternatively here's a diff…

Code

Index: ocf_members_action.php
===================================================================
--- ocf_members_action.php   (revision 2414)
+++ ocf_members_action.php   (working copy)
@@ -710,10 +710,21 @@
       }
    }
 
+   // Set custom profile field values
+   $all_fields_types=collapse_2d_complexity('id','cf_type',$all_fields);
+   $changes=array();
    foreach ($custom_fields as $field=>$value)
    {
-      if (!is_null($value)) ocf_set_custom_field($member_id,$field,$value);
+      if (!is_null($value))
+      {
+         $change=ocf_set_custom_field($member_id,$field,$value,$all_fields_types[$field],true);
+         if (!is_null($change)) $changes=array_merge($changes,$change);
+      }
    }
+   if (count($changes)!=0)
+   {
+      $GLOBALS['FORUM_DB']->query_update('f_member_custom_fields',$changes,array('mf_member_id'=>$member_id),'',1);
+   }
 
    $old_primary_group=$GLOBALS['OCF_DRIVER']->get_member_row_field($member_id,'m_primary_group');
 
@@ -1079,10 +1090,14 @@
  * @param  MEMBER      The member.
  * @param  AUTO_LINK The field being set.
  * @param  LONG_TEXT The value of the field.
+ * @param  ID_TEXT    The field type (NULL: look it up).
+ * @param  boolean    Whether to defer the change, by returning a result change rather than doing it right away.
+ * @return ?array      Mapping change (NULL: none / can't defer).
  */
-function ocf_set_custom_field($member_id,$field,$value)
+function ocf_set_custom_field($member_id,$field,$value,$type=NULL,$defer=false)
 {
-   $type=$GLOBALS['FORUM_DB']->query_value('f_custom_fields','cf_type',array('id'=>$field));
+   if (is_null($type)) $type=$GLOBALS['FORUM_DB']->query_value('f_custom_fields','cf_type',array('id'=>$field));
+
    if ((is_null($value)) && ($type!='integer') && ($type!='float')) $value='';
    if (($type=='short_trans') || ($type=='long_trans'))
    {
@@ -1097,8 +1112,13 @@
       }
    } else
    {
-      $GLOBALS['FORUM_DB']->query_update('f_member_custom_fields',array('field_'.strval(intval($field))=>$value),array('mf_member_id'=>$member_id),'',1);
+      $change=array('field_'.strval(intval($field))=>$value);
+      if (!$defer)
+         $GLOBALS['FORUM_DB']->query_update('f_member_custom_fields',$change,array('mf_member_id'=>$member_id),'',1);
+      return $change;
    }
+   
+   return NULL;
 }


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#46302
Avatar

Fan in training

Chris,

Thanks for the immediate response. i copied the ocf_members_action.php file into sources directory. But when i clicked on edit profile, i got this error. something like undefined index: m_password_compat_scheme (ocportal:3.2.10….)


Anything i missed?

regards,

Madhavi.
Back to the top
 
Posted
Rating:
#46303
Avatar

Hi,

This is a very old version, so won't be compatible with this file.

It's no longer actively developed.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: