Jump to content

update module row from other function

Recommended Posts

the documentation on module development i am finding to be very disappointing. It requires a lot of implied knowledge on blesta, that i would not have as i am not the creator.

So i am getting stuck at almost every part of our module development.

So far i am wanting to update a module_row_meta key value from other functions in the module. This is because our API uses a rotating API auth tokens. So each API call replies with a new token, thus it needs to be updated in the database to be used on the next API call.

Does anyone know how to update the module_row_meta table from other functions within the module? i keep getting told to just look at the other modules, but i see no other module doing this.

Share this post

Link to post
Share on other sites

Hi there, sorry to hear your experience has been difficult. Thanks for your feed back on the other post, we really appreciate it.

That being said, I don't think there are any module currently doing this.  Here are two ways that should work to go about this.

1. Load the Record component ( Loader::loadComponents($this, ['Record']); ) and manually change the database.  $this->Record->where('module_row_meta.module_row_id', '=', $module_row_id)->update('module_row_meta', ['api_key' => 'new_api_key']);

2. Use the ModuleManager model (Loader::loadModels($this, ['ModuleManager'])).  The method you would use is ::editRow().  $this->ModuleManager->editRow($module_row_id, ['api_key' => 'new_api_key']);  One thing to keep in mind is that this method replaces all the meta data for that row so you might want to load the current meta data, update it, then submit it.

$meta_data = $this->ModuleManager->getRowMeta($module_row_id);

$vars = [];
foreach ($meta_data as $meta) {
	$vars[$meta->key] = ($meta->key == 'api_key' ? 'new_api_key' : $meta->value);

$this->ModuleManager->editRow($module_row_id, $vars);

Hopefully that is helpful.



Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...