not able to edit metadata

Hi there,

I´m having trouble trying to change the metadata of an object. I´m using the same code to create and edit the metadata. The metadata info comes from a form. And the first time the code adds the metadata correctly but next time I try to edit it doesn´t do anything. It keeps the original values. This is the code:

// get the form input
    $certificate_spec = get_entity($certificate_guid);
    $ind ++;
    $certificate_spec->ref1 = $_POST['learning_need'.$ind];
    $certificate_spec->ref2 = $_POST['objective'.$ind];
    $certificate_spec->ref3 = $_POST['outcome'.$ind];
    $certificate_spec->imp1 = $_POST['before_course'.$ind];
    $certificate_spec->imp2 = $_POST['after_course'.$ind];
    $certificate_spec->imp3 = $_POST['changes'.$ind];

I´ll appreciate any help.

 

thanks

  • DhrupDeScoop, well done for holding up the Elgg flag. If I knew about the inner workings of Elgg, then I'd be helping out too. Metadata is something I've not got to. I knew more than I did, but not enough to be comfortable advising on this kind of thing.

  • here are the two lines for updating:

    remove_metadata($certificate_guid, 'ref1');
    create_metadata($certificate_guid, 'ref1', $val1, 'text', $_SESSION['user']->guid, ACCESS_PUBLIC);

     

    note: I tried the differents type of access...

     

  • try :-

    remove_metadata($certificate_guid, 'ref1');
    create_metadata($certificate_guid, 'ref1', $val1, 'text', $certificate_guid, ACCESS_PUBLIC);

     

  • no luck. As soon as I remove the admin privileges from the user, it doesn´t edit. :(

    thanks anyway and enjoy the rest of your weekend.

  • Depending on who is executing the code, and who has write access to the metadata, it may be that you need to use the permissions plugin hook to grant permission.

     

    Try this:

    in start.php

        // override permissions for the certificate_permission_overwrite context
        register_plugin_hook('permissions_check', 'all', 'certificate_permissions_check');   

        function certificate_permissions_check(){

             if(get_context() == "certificate_permission_overwrite"){

                  return true;

             }

             return NULL;

        }

     

    And where you are editing your metadata prepend and append the following:

    $context = get_context();

    set_context('certificate_permission_overwrite');

     

    // do you metadata stuff here

     

    set_context($context);