/**
* Store data to the appropriate table
*
* @param array $data Data to be stored
* @param TableInterface $table Table Object
* @param string $primaryKey The primary key name
*
* @return boolean True on success
*
* @since 3.1
* @throws \Exception
*/
protected function store($data, TableInterface $table = null, $primaryKey = null)
{
if (!$table) {
$table = Table::getInstance('Ucm');
}
$ucmId = $data['ucm_id'] ?? null;
$primaryKey = $primaryKey ?: $ucmId;
if (isset($primaryKey)) {
$table->load($primaryKey);
}
try {
$table->bind($data);
} catch (\RuntimeException $e) {
throw new \Exception($e->getMessage(), 500, $e);
}
try {
$table->store();
} catch (\RuntimeException $e) {
throw new \Exception($e->getMessage(), 500, $e);
}
return true;
}