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.


Query function to use when needing to translate?

Login / Search

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

Community saint

Ok Chris I need your expertise again and believe me I have been looking through the code to solve myself but there are so many DB functions and I am tired and getting confused about the best approach to my query where as you'll know the answer in 30 secs  compared to my last hour+  of studying the functions and trying decipher heads or tails!

Can you please tell me what is wrong with this function (obviously the query is not returning the results I expect:

Code

   function import_ocf_remove_old_groups(){
      $ignore_groups = array('Administrators','Super-moderators','Newbie','Super-members','Probation');
      $rows = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT g.id, t.text_original FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_groups AS g INNER JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate AS t ON g.g_name = t.id');
      if(!$rows == NULL){
         foreach ($rows as $row){
            if(in_array($row[1],$ignore_groups)) continue;
            ocf_delete_group($row[0]);
         }
      }
   }
Back to the top
 
Posted
Rating:
#90836
Avatar

Community saint

Well I tried the following and while I got no errors this time it didn't delete the groups as expected. hmmmm

Code

   function import_ocf_remove_old_groups(){
      $ignore_groups = array('Administrators','Super-moderators','Newbie','Super-members','Probation');
      $rows = $GLOBALS['FORUM_DB']->query_select($GLOBALS['FORUM_DB']->get_table_prefix().'f_groups g INNER JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON (g.g_name = t.id)', array('g.id','t.text_original'));
      if(!$rows == NULL){
         foreach ($rows as $row){
            if(in_array($row['text_original'],$ignore_groups)) continue;
            ocf_delete_group($row['id']);
         }
      }
   }
Back to the top
 
Posted
Rating:
#90839
Avatar

Community saint

Don't you need?:

Code

require_code('ocf_groups_action');
require_code('ocf_groups_action2');

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#90842
Avatar

Community saint

This is inside an importer so those codes would have been included already
Back to the top
 
Posted
Rating:
#90843
Avatar

Community saint

Is $row['id'] a string? If so use intval($row['id']) .
 

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#90844
Avatar

Community saint

I don't think it should be its stored as an int in the db unless the query function is responsible for converting it. I think I may have to start writing to a log to see what's returning from my query. Is there  built n logging function I can call or must I write one to test this code?
Back to the top
 
Posted
Rating:
#90845
Avatar

Community saint

Ok. Looking at the underlying query function db_get_query_rows in mysql.php it certainly appears to be converting it to an int.

Don't know if there is any logging option but you can throw in a few well placed file_put_contents() calls .

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#90846
Avatar

$rows = $GLOBALS['FORUM_DB']->query_value_null_ok_full

"query_value_null_ok_full" returns a single field from a single row. "query" is what you need.

v10 is actually renaming these functions a bit because the naming is a bit confusing.

query – run a query
value – return a single value
null_ok – if there is no result, represent that as NULL rather than triggering an error
full – don't build up the SQL in PHP array syntax, take the SQL directly


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:
#90857
Avatar

Community saint

I tried query and still no go. I am getting so frustrated.  Here is a the query as works absolutely fine when run directly in mySQl DB

SELECT g.id, t.text_original FROM f_groups AS g INNER JOIN translate AS t ON g.g_name = t.id

I can't figure out how for the life of me to make that query work on ocP using ocP's DB functions!

Could you please show me how to get my associative array from this query using ocp?
Back to the top
 
Posted
Rating:
#90858
Avatar

I tested via OcCLE and it seemed to work:

Code

:var_dump($GLOBALS['FORUM_DB']->query('SELECT g.id, t.text_original FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_groups AS g INNER JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate AS t ON g.g_name = t.id'));

All I can think is if you're not running OCF, FORUM_DB would be incorrect, it'd be SITE_DB – an importer should always use SITE_DB when importing a forum because you're looking towards it running from OCF later but it might not be yet.


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:
#90859
Avatar

Community saint

lol that idea was nagging at me that I might need to use SITE DB but since other areas of the importer where using FORUM DB I figured nah that can't be it. But I will try.
Back to the top
 
Posted
Rating:
#90860
Avatar

Community saint

OMG I finally found the problem! "Guests" was not in my ignore array so when every the query was correct I would get errors because you can't delete the guest group! (at least I think that was the problem). Woot what a hair puller! lol ( I did change to SITE DB as well but it had erred again till I notice something in the stack trace about the argument being 1 in the delete group function so I looked up group 1 and realized it was a guest group
Back to the top
 
Posted
Rating:
#90872
Avatar

Community saint

Ok so this is working now but I have a question:

Since I delete the groups using the ocf_delete_group function when I add new groups their order numbers and group ids continue from where the current indexes left off which seems kinda messy to me and I was thinking about resetting the index and order numbers.  Do you foresee a problem if I were to do this?
Back to the top
 
Posted
Rating:
#90873
Avatar

Community saint

hmm ok nearly everything seems to work perfect but one thing I can't explain:

I can't seem to merge Administrator with Administrators? The Global Moderator gets merged with Super-Moderator  but not administrator and I can't figure out why?


here is function:

Code

   function import_ocf_groups($db,$table_prefix)
   {
      global $ADDITIONAL_DATA;

      $avatar_max_width =  !empty($ADDITIONAL_DATA['avatar_max_width'])? $ADDITIONAL_DATA['avatar_max_width'] : 100; //added by Duck
      $avatar_max_height = !empty($ADDITIONAL_DATA['avatar_max_height'])? $ADDITIONAL_DATA['avatar_max_height'] : 100; //added by Duck
      $max_attachments_upload = !empty($ADDITIONAL_DATA['maxattachments'])? $ADDITIONAL_DATA['maxattachments'] : 10; //added by Duck

      $rows=$db->query('SELECT * FROM '.$table_prefix.'membergroups ORDER BY ID_GROUP');
      foreach ($rows as $row)
      {
         if (import_check_if_imported('group',strval($row['ID_GROUP']))) continue; //Edited by Duck

         $group_name = (trim($row['groupName'])=='Administrator')?'Administrators':$row['groupName'];
         $group_name=($row['groupName']=='Global Moderator')?'Super-moderators':$row['groupName'];
         $is_super_admin=0;
         $is_super_moderator=0;

         $id_new=$GLOBALS['FORUM_DB']->query_value_null_ok('f_groups g LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON g.g_name=t.id WHERE '.db_string_equal_to('text_original',$group_name),'g.id');
         if (is_null($id_new))
         {
            $id_new=ocf_make_group($group_name,0,$is_super_admin,$is_super_moderator,'','',NULL,NULL,NULL,5,0,5,$max_attachments_upload,$avatar_max_width,$avatar_max_height,30000); //Edited by Duck
         }

         // privileges
         set_specific_permission($id_new,'allow_html',true);

         if (!import_check_if_imported('group',strval($row['ID_GROUP'])))
            import_id_remap_put('group',strval($row['ID_GROUP']),$id_new);
      }
      $this->update_group_promotions($db,$table_prefix);
   }
Back to the top
 
Posted
Rating:
#90877
Avatar

Hehe,

Code

       $group_name = (trim($row['groupName'])=='Administrator')?'Administrators':$row['groupName'];
         $group_name=($row['groupName']=='Global Moderator')?'Super-moderators':$row['groupName'];

You're overwriting the result of the first line with the second.


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:
#90878
Avatar

Duck said

Ok so this is working now but I have a question:

Since I delete the groups using the ocf_delete_group function when I add new groups their order numbers and group ids continue from where the current indexes left off which seems kinda messy to me and I was thinking about resetting the index and order numbers.  Do you foresee a problem if I were to do this?

Gaps in IDs aren't going to really cause any problems, but trying to fix them up would be really hard – you'd need to adjust a lot of foreign keys to match changes.

Why the group deletion? The importers are designed to allow merging, potentially the ocPortal site is already in quite heavy use before the import so personally I'd do more like what you were talking about in the post I just replied to – merging in ones that have the same role.


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:
#90879
Avatar

( I did change to SITE DB as well but it had erred again till I notice something in the stack trace about the argument being 1 in the delete group function so I looked up group 1 and realized it was a guest group

I was wrong about SITE_DB/FORUM_DB.

ocPortal actually does some juggling in importers, and it always confuses me but it's necessary.
A function (in sources/import.php) is called before import:
ocf_over_local()
which sets FORUM_DB to be the same as SITE_DB. This is what allows OCF to run even though the site may not actually be using OCF as its normal forum driver.

There's another function, ocf_over_msn(), which switches it back, if an importer needs to commune with the true forum driver for some reason.

Importer code often flicks between these modes.


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
Item has a rating of 5 (Liked by Chris Graham)  
Rating:
#90883
Avatar

Community saint

Chris Graham said

Hehe,
You're overwriting the result of the first line with the second.
DOH! Ok so I was tired and wasn't thinking straight this is why second pair of eyes is so helpful for reminding you what a dork you are sometimes lol!

Chris Graham said

Why the group deletion?
Well I am testing with a fresh install of ocPortal and SMF each and I figure most of the time the person will be importing and want mostly their SMF groups and not the default ocPortal groups (like Local Hero etc) so I figure I would allow a little clean up. The option is selectable as an import option though so users don't have to delete them if they don't want (like in the case of an established ocPortal site) it is also for this reason I turned the function around from deleting via an ignore list to deleting via a delete list. In case they import their SMF groups first but forgot to check delete groups and then ran it again with it checked. I just put in the common default ocPortal groups like local hero etc but someone could edit that array if they wished. The delete also happens before the import so if there were the same named groups in SMF they would just be recreated but at least with SMF settings.

Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: