if (!empty($_POST['meta_json']) && $guard->hasPermission('importmetadata', $entity->getWorkflow(), $user->getType())) {
     function convert_stdobject_to_array($object)
     {
         $object = (array) $object;
         foreach ($object as $key => $value) {
             if (is_array($value) || is_object($value) && get_class($value) === 'stdClass') {
                 $object[$key] = convert_stdobject_to_array($value);
             }
         }
         return $object;
     }
     try {
         $metaStdClass = json_decode($_POST['meta_json']);
         if ($metaStdClass) {
             $metaArray = convert_stdobject_to_array($metaStdClass);
             $metaArray = $mcontroller->arrayFlattenSep(':', $metaArray);
             if ($metaArray['entityid'] === $mcontroller->getEntity()->getEntityid()) {
                 foreach ($metaArray as $key => $value) {
                     if ($mcontroller->hasMetadata($key)) {
                         echo "Updating: {$key}<br />" . PHP_EOL;
                         $mcontroller->updateMetadata($key, $value);
                     } else {
                         echo "Adding: {$key}<br />" . PHP_EOL;
                         $mcontroller->addMetadata($key, $value);
                     }
                 }
                 $update = TRUE;
                 $msg = 'status_metadata_parsed_ok';
             } else {
                 $msg = 'error_metadata_wrong_entity';
             }