Jump to content

Member Sync


Norbee.
 Share

Recommended Posts

Hey. I would ask some help. I managed to make a new application for my gameservers which update the user stuffs ( admin/vip etc) 

So i have a Member Sync extension everytime when user update the profile  which is update data from custome field into the gameserver DB.  I have custome row when the user update the custome field that custome row is change to 1 and i created a task which is reset the custome row to 0 every day.

Is there some query code for check the custome row? if its 1 then i want to show an error message instead of execute my code.

 

public function onProfileUpdate( $member, $changes )
	{
		
				
				thereismycustomecode.

	}

 

Link to comment
Share on other sites

Yes, Aiwa's information is correct bu do not try to show an error in a memberSync extension. Often, these are executed by background tasks, which may (or may not) be running via cron - not user would ever see an error message.

Why would you want to show a message specifically? Depending upon your answer, you may need to create a hook to handle that part differently.

Link to comment
Share on other sites

20 hours ago, Aiwa said:

$member contains the existing member object, minus the changes. 

$changes includes the changes that are being made. 

Check the $changes array for your custom row. If it isn't there, ignore. 

You want to be really careful about how you handle errors in a memberSync extension. 

Hmm. I will check what i can do without destroying the whole forum.  A example would be nice 😄 

3 hours ago, bfarber said:

Yes, Aiwa's information is correct bu do not try to show an error in a memberSync extension. Often, these are executed by background tasks, which may (or may not) be running via cron - not user would ever see an error message.

Why would you want to show a message specifically? Depending upon your answer, you may need to create a hook to handle that part differently.

Some time people too lazy to read something. Thats why i want a big red message.

Link to comment
Share on other sites

55 minutes ago, Norbee. said:

Hmm. I will check what i can do without destroying the whole forum.  A example would be nice 😄 

Some time people too lazy to read something. Thats why i want a big red message.

If you want a big red message when the user makes a boo boo, memberSync likely isn't for you. You need to be a little more clear about what you're trying to achieve. 

Multiple applications likely rely on memberSync. If you throw an error, you force it to bail the current execution path. Which means some apps may not get the change data because you halted before it got to them. 

In my applications that use memberSync, if there is an issue, I log the error in a table controlled by my app, and return nothing. I then display that error on the profile, if present, when the user views the page. You do NOT halt the memberSync and redirect back to a user profile with an error message. 

Edited by Aiwa
Link to comment
Share on other sites

So i drop the hole membersync. Instead i made a little Account Settings menu with 2 Form. ( I think this is the good way 😄

Looks like this. (Well this is just the 2 form)

image.thumb.png.9a69bbc7f0df72c955ae8426e89c2045.png

Also i have 3 table for my 3 gameserver every table the same structure. server1/server2/server3 with 3 column (memberid/row1/row2/ ) how i can send from the form  what is the user write there to update the row1/row2 column on all 3 table(server1/server2/server3)

Well so complicated for me 😄.

 

//<?php

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	exit;
}

class ebacore_hook_adminbealitasok extends _HOOK_CLASS_
{
	    public function _adminbealitasok()
		{
			 $output .= '<div id="acpWarnings">
	                    '.$other.'
	                    <div class="ipsMessage ipsMessage_info">
	                        <h4 class="ipsMessage_title">asdasd</h4>
	                        <div class="ipsType_normal ipsType_reset">asdasdasdasdasdasdaasdasdasd</b>.</div>
	                    </div>
	                </div>';
	
	        $form = new \IPS\Helpers\Form('form');
	        $member = \IPS\Member::loggedIn();
			
	
	       $form->add(new \IPS\Helpers\Form\Text('asd'));
		   $form->add(new \IPS\Helpers\Form\Text('asd2'));
	
			
	       
	        $output .= $form;
	
	        return $output;
			}

}

 

Link to comment
Share on other sites

Great it is working now 😄when i manually enter the memberid. When i try to get the memberid i got error 

ErrorException: Object of class IPS\Member could not be converted to string (4096)
$member = \IPS\Member::loggedIn();
Link to comment
Share on other sites

Well atleast i try :biggrin: 

Cannot use object of type IPS\Db\Select as array


 

//<?php

/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
	exit;
}

class ebacore_hook_adminbealitasok extends _HOOK_CLASS_
{
		public function _adminbealitasok()
		{
	
	        $form = new \IPS\Helpers\Form('form');
	        $member = \IPS\Member::loggedIn()->member_id;
			$admininfo = \IPS\Db::i()->select( '*', 'ebacore_adminok_awp', array( 'felhid=?', $member ) );
			
			
			
	       $form->add(new \IPS\Helpers\Form\Text('ebacore_steamid', $admininfo["steamid"], FALSE, [], NULL, NULL, NULL, 'ebacore_steamid'));
		   $form->add(new \IPS\Helpers\Form\Text('ebacore_jelszo', $admininfo["steamid"], FALSE, [], NULL, NULL, NULL, 'ebacore_jelszo'));
		   \IPS\Output::i()->output .= $form;
		  
		   
		    if ($values = $form->values()) {
	          
					\IPS\Db::i()->update( 'ebacore_adminok_awp', array( 'steamid' => $values['steamid'] ), array( 'felhid=?', $member ) );
					\IPS\Db::i()->update( 'ebacore_adminok_awp', array( 'jelszo' => $values['steamid'] ), array( 'felhid=?', $member ) );

	        }	
			
			\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=system&controller=settings&area=adminbealitasok' ), 'saved' );
			
			
		}
		
}	

 

Link to comment
Share on other sites

Hmm after press the save button i got strange Undefined index: steamid. 

I check some doc  and i put there $admininfo = $admininfo->forceIndex('steamid'); after the query.

And i got:

Call to a member function forceIndex() on array

 

 

Link to comment
Share on other sites

You don't want to use forceIndex for this purpose.

$admininfo = \IPS\Db::i()->select( '*', 'ebacore_adminok_awp', array( 'felhid=?', $member ) )->first();

If $admininfo['steamid'] is giving you an undefined index, it means that there was no steamid column returned (but a row was returned, otherwise you'd have ran into an UnderflowException).

Link to comment
Share on other sites

Hello,

1. Pay attention on

$form->add(new \IPS\Helpers\Form\Text('ebacore_steamid', $admininfo["steamid"], FALSE, [], NULL, NULL, NULL, 'ebacore_steamid'));
$form->add(new \IPS\Helpers\Form\Text('ebacore_jelszo', $admininfo["steamid"], FALSE, [], NULL, NULL, NULL, 'ebacore_jelszo'));

The $values is array with keys ebacore_steamid and ebacore_jelszo

  • $values['ebacore_steamid']
  • $values['ebacore_jelszo']

2.

\IPS\Db::i()->update( 'ebacore_adminok_awp', array( 'steamid' => $values['steamid'] ), array( 'felhid=?', $member ) );
\IPS\Db::i()->update( 'ebacore_adminok_awp', array( 'jelszo' => $values['steamid'] ), array( 'felhid=?', $member ) );

You use $values['steamid'] but you don't have it. In this case you get an Undefined index: steamid. 


BTW why do you use ['steamid'] for both inputs (ebacore_steamid and ebacore_jelszo)?


public function _adminbealitasok()
{
	try
	{
		$admininfo = \IPS\Db::i()->select( '*', 'ebacore_adminok_awp', array( 'felhid=?', \IPS\Member::loggedIn()->member_id ) )->first();
	}
	catch (\Exception $e)
	{
		\IPS\Output::i()->error( 'row_not_found', '1EBACORE100/1', 404, '' );		
	}

	$form = new \IPS\Helpers\Form;

	$form->add(new \IPS\Helpers\Form\Text('ebacore_steamid', $admininfo["steamid"] ?? NULL, FALSE, [], NULL, NULL, NULL, 'ebacore_steamid'));
	$form->add(new \IPS\Helpers\Form\Text('ebacore_jelszo', $admininfo["jelszo"] ?? NULL, FALSE, [], NULL, NULL, NULL, 'ebacore_jelszo'));
	
	if ($values = $form->values())
	{
		\IPS\Db::i()->update( 'ebacore_adminok_awp', array( 'steamid' => $values['ebacore_steamid'], 'jelszo' => $values['ebacore_jelszo'] ), array( 'felhid=?', \IPS\Member::loggedIn()->member_id ) );
		
		\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=system&controller=settings&area=adminbealitasok' ), 'saved' );
	}	
	
	\IPS\Output::i()->output .= $form;
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...