mediamosa_browse_collection_delete_confirm_form_submit

Versions
mediamosa-21
mediamosa_browse_collection_delete_confirm_form_submit($form, &$form_state)

Submit handler for deletion collection.

See also

mediamosa_browse_collection_delete_confirm_form()

Code

sites/all/modules/mediamosa/maintenance/browse/mediamosa_maintenance_browse_collection.inc, line 553

<?php
function mediamosa_browse_collection_delete_confirm_form_submit($form, &$form_state) {

  // Remove all links
  $coll_id = $form_state['values']['coll_id'];

  // Get the collection.
  $collection = mediamosa_collection::get($coll_id);

  // Check if the user also wants to remove all assets from the collection first
  if ($form_state['values']['truncate'] === 1) {

    // Get all asset_ids.
    $asset_ids = mediamosa_asset_collection::get_asset_ids_by_coll_ids(array($coll_id))->fetchCol();

    if (!empty($asset_ids)) {
      $url = strtr('collection/@coll_id/asset_relation/delete', array('@coll_id' => $coll_id));

      $asset_ids_todo = array();

      // As long we got ids, we'll continue.
      while (count($asset_ids)) {
        for ($x = 0; $x < 5000 && count($asset_ids); $x++) {
          $asset_ids_todo[] = array_pop($asset_ids);
        }

        // Do request to get total of assets in collection.
        mediamosa_response_connector::static_do_restcall_drupal($url, 'POST', array('app_id' => $collection[mediamosa_collection_db::APP_ID], 'asset_id' => $asset_ids_todo, 'user_id' => $collection[mediamosa_collection_db::OWNER_ID]));
      }
    }
  }

  // Delete the collection.
  $url = strtr('collection/@coll_id/delete', array('@coll_id' => $coll_id));
  $result = mediamosa_response_connector::static_do_restcall_drupal($url, 'POST', array('app_id' => $collection[mediamosa_collection_db::APP_ID], 'user_id' => $collection[mediamosa_collection_db::OWNER_ID]));

  if (in_array((int)$result['header']['request_result_id'], array(mediamosa_error::ERRORCODE_OKAY, mediamosa_error::ERRORCODE_EMPTY_RESULT))) {
    drupal_set_message('The collection has been deleted.');
    drupal_goto('admin/mediamosa/browse/collection');
  }

  drupal_goto('admin/mediamosa/browse/collection/' . rawurlencode($coll_id));
}
?>