Browse Source

fixed conflict

pull/164/head
William Panting 12 years ago
parent
commit
af6a9f4b25
  1. 116
      MimeClass.inc
  2. 189
      api/fedora_utils.inc
  3. 116
      fedora_repository.module

116
MimeClass.inc

@ -6,26 +6,27 @@
* @file
* This class inspired by Chris Jean's work, here:
* http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/
*
* It does some MIME trickery, inspired by the need to to deal with Openoffice
* and MS Office 2007 file formats -- which are often mis-interpreted by
*
* It does some MIME trickery, inspired by the need to to deal with Openoffice
* and MS Office 2007 file formats -- which are often mis-interpreted by
* mime-magic, fileinfo, and the *nix `file` command.
*
* In Drupal 6, we also make use of file_get_mimetype. See:
* In Drupal 6, we also make use of file_get_mimetype. See:
* http://api.drupal.org/api/function/file_get_mimetype/6
* ... however this only provides a uni-directional lookup (ext->mime).
* While I don't have a specific use case for a mime->extension lookup, I think
* it's good to have in here.
*
*
* Drupal 7 will have better mime handlers. See:
* http://api.drupal.org/api/function/file_default_mimetype_mapping/7
*
*/
class MimeClass {
private $private_mime_types = array(
/**
* This is a shortlist of mimetypes which should catch most
/*
* This is a shortlist of mimetypes which should catch most
* mimetype<-->extension lookups in the context of Islandora collections.
*
* It has been cut from a much longer list.
@ -33,26 +34,26 @@ class MimeClass {
* Two types of mimetypes should be put in this list:
* 1) Special emerging formats which may not yet be expressed in the system
* mime.types file.
* 2) Heavily used mimetypes of particular importance to the Islandora
* project, as lookups against this list will be quicker and less
* 2) Heavily used mimetypes of particular importance to the Islandora
* project, as lookups against this list will be quicker and less
* resource intensive than other methods.
*
* Lookups are first checked against this short list. If no results are found,
* then the lookup function may move on to check other sources, namely the
* system's mime.types file.
* Lookups are first checked against this short list.
* If no results are found, then the lookup function may move
* on to check other sources, namely the system's mime.types file.
*
* In most cases though, this short list should suffice.
*
*
* If modifying this list, please note that for promiscuous mimetypes
* (those which map to multiple extensions, such as text/plain)
* The function get_extension will always return the *LAST* extension in this list,
* so you should put your preferred extension *LAST*.
* The function get_extension will always return the *LAST* extension
* in this list, so you should put your preferred extension *LAST*.
*
* e.g...
* e.g...
* "jpeg" => "image/jpeg",
* "jpe" => "image/jpeg",
* "jpg" => "image/jpeg",
*
*
* $this->get_extension('image/jpeg') will always return 'jpg'.
*
*/
@ -89,7 +90,7 @@ class MimeClass {
'ksp' => 'application/x-kspread',
'kwt' => 'application/x-kword',
'kwd' => 'application/x-kword',
// ms office 97:
// MS office 97:
'doc' => 'application/msword',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
@ -113,9 +114,9 @@ class MimeClass {
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
'sldm' => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
// wordperfect (who cares?):
// Wordperfect (who cares?):
'wpd' => 'application/wordperfect',
// common and generic containers:
// Common and generic containers:
'pdf' => 'application/pdf',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
@ -185,15 +186,18 @@ class MimeClass {
"ogg" => "audio/ogg",
"flac" => "audio/x-flac",
"wav" => "audio/vnd.wave",
// compressed formats: (note: http://svn.cleancode.org/svn/email/trunk/mime.types)
/* Compressed formats:
(note: http://svn.cleancode.org/svn/email/trunk/mime.types).*/
"tgz" => "application/x-gzip",
"gz" => "application/x-gzip",
"tar" => "application/x-tar",
"gtar" => "application/x-gtar",
"zip" => "application/x-zip",
// others:
// others:
'bin' => 'application/octet-stream',
'json' => 'application/json',
);
private $private_file_extensions;
private $system_types;
private $system_exts;
@ -204,10 +208,10 @@ class MimeClass {
*/
public function __construct() {
// populate the reverse shortlist:
// Populate the reverse shortlist:
$this->private_file_extensions = array_flip($this->private_mime_types);
// pick up a local mime.types file if it is available
// Pick up a local mime.types file if it is available.
if (is_readable('mime.types')) {
$this->etc_mime_types = 'mime.types';
}
@ -219,7 +223,7 @@ class MimeClass {
* for backwards-compatibility with our old mimetype class.
*
* @param type $filename
* @return type
* @return type
*/
public function getType($filename) {
return $this->get_mimetype($filename);
@ -227,40 +231,47 @@ class MimeClass {
/**
* function: get_mimetype
* description: returns a mimetype associated with the file extension of $filename
* description: returns a mimetype associated with the
* file extension of $filename
*
* @param type $filename
* @param type $debug
* @return type
* @return string
* mimetype associated with the file extension of $filename
*/
public function get_mimetype($filename, $debug = FALSE) {
$ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
if (!empty($this->private_mime_types[$ext])) {
if (TRUE === $debug)
if (TRUE === $debug) {
return array('mime_type' => $this->private_mime_types[$ext], 'method' => 'from_array');
}
return $this->private_mime_types[$ext];
}
if (function_exists('file_get_mimetype')) {
$drupal_mimetype = file_get_mimetype($filename);
if ('application/octet-stream' != $drupal_mimetype) {
if (TRUE == $debug)
if (TRUE == $debug) {
return array('mime_type' => $drupal_mimetype, 'method' => 'file_get_mimetype');
}
return $drupal_mimetype;
}
}
if (!isset($this->system_types))
if (!isset($this->system_types)) {
$this->system_types = $this->system_extension_mime_types();
}
if (isset($this->system_types[$ext])) {
if (TRUE == $debug)
if (TRUE == $debug) {
return array('mime_type' => $this->system_types[$ext], 'method' => 'mime.types');
}
return $this->system_types[$ext];
}
if (TRUE === $debug)
if (TRUE === $debug) {
return array('mime_type' => 'application/octet-stream', 'method' => 'last_resort');
}
return 'application/octet-stream';
}
@ -270,34 +281,38 @@ class MimeClass {
*
* @param type $mime_type
* @param type $debug
* @return type
* @return type
*/
public function get_extension($mime_type, $debug = FALSE) {
if (!empty($this->private_file_extensions[$mime_type])) {
if (TRUE == $debug)
if (TRUE == $debug) {
return array('extension' => $this->private_file_extensions[$mime_type], 'method' => 'from_array');
}
return $this->private_file_extensions[$mime_type];
}
if (!isset($this->system_exts))
if (!isset($this->system_exts)) {
$this->system_exts = $this->system_mime_type_extensions();
}
if (isset($this->system_exts[$mime_type])) {
if (TRUE == $debug)
if (TRUE == $debug) {
return array('extension' => $this->system_exts[$mime_type], 'method' => 'mime.types');
}
return $this->system_exts[$mime_type];
}
if (TRUE == $debug)
if (TRUE == $debug) {
return array('extension' => 'bin', 'method' => 'last_resort');
}
return 'bin';
}
/**
* function: system_mime_type_extensions
* description: populates an internal array of mimetype/extension associations
* from the system mime.types file, or a local mime.types if one is found (see
* __constuctor).
* from the system mime.types file, or a local mime.types if one is found (see
* __constuctor).
* return: array of mimetype => extension
*/
private function system_mime_type_extensions() {
@ -306,15 +321,18 @@ class MimeClass {
$file = fopen($this->etc_mime_types, 'r');
while (($line = fgets($file)) !== FALSE) {
$line = trim(preg_replace('/#.*/', '', $line));
if (!$line)
if (!$line) {
continue;
}
$parts = preg_split('/\s+/', $line);
if (count($parts) == 1)
if (count($parts) == 1) {
continue;
}
// A single part means a mimetype without extensions, which we ignore.
$type = array_shift($parts);
if (!isset($out[$type]))
if (!isset($out[$type])) {
$out[$type] = array_shift($parts);
}
// We take the first ext from the line if many are present.
}
fclose($file);
@ -325,8 +343,8 @@ class MimeClass {
/**
* function: system_mime_type_extensions
* description: populates an internal array of mimetype/extension associations
* from the system mime.types file, or a local mime.types if one is found (see
* __constuctor).
* from the system mime.types file, or a local mime.types if one is found (see
* __constuctor).
* return: array of extension => mimetype
*/
private function system_extension_mime_types() {
@ -335,15 +353,18 @@ class MimeClass {
$file = fopen($this->etc_mime_types, 'r');
while (($line = fgets($file)) !== FALSE) {
$line = trim(preg_replace('/#.*/', '', $line));
if (!$line)
if (!$line) {
continue;
}
$parts = preg_split('/\s+/', $line);
if (count($parts) == 1)
if (count($parts) == 1) {
continue;
}
// A single part means a mimetype without extensions, which we ignore.
$type = array_shift($parts);
foreach ($parts as $part)
foreach ($parts as $part) {
$out[$part] = $type;
}
}
fclose($file);
}
@ -351,4 +372,3 @@ class MimeClass {
}
}

189
api/fedora_utils.inc

@ -1,23 +1,23 @@
<?php
/**
* @file
* Base utilities used by the Islandora fedora module.
*/
if (!function_exists('str_getcsv')) {
/**
* Functions that emulate php5.3 functionality for backwards compatiablity
*
* @param type $input
* @param type $delimiter
* @param type $enclosure
* @param type $escape
* @param type $eol
* @return type
*
* @return type
*/
function str_getcsv($input, $delimiter=',', $enclosure='"', $escape=NULL, $eol=NULL) {
function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = NULL, $eol = NULL) {
$temp = fopen("php://memory", "rw");
fwrite($temp, $input);
fseek($temp, 0);
@ -29,16 +29,16 @@ if (!function_exists('str_getcsv')) {
}
/**
*
*
* Utility method to get data from a url location using curl_exec and return
*
*
* This method takes identical parameters to do_curl_ext and passes them
* directly to do_curl_ext. The output from do_curl_ext is processed into
* either a TRUE, FALSE, or NULL value.
*
*
* This method exists for historical reasons as existing code makes use of
* do_curl directly and expects a simple return value and not an array.
*
*
* @param $url
* URL to be accessed by the function
* @param $return_to_variable
@ -49,8 +49,8 @@ if (!function_exists('str_getcsv')) {
* Number of variable sot be posted
* @param $post
* Whether the curl_exec is done as a "get" or a "post"
*
* @return
*
* @return mixed
* TRUE, FALSE, NULL, or the data returned from accessing the URL
*/
function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post = NULL) {
@ -59,18 +59,17 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
}
/**
*
* Utility method to get data from a url location using curl_exec
*
*
* This method takes a URL and three associated parameters and initializes the
* structure required to make a call to curl_exec. As a part of the
* initialization the permissions associated with the (global) user are added
* to the call. This ensures access to any potentially user restricted URLs.
*
*
* Various defaults are used for the parameters required by curl_exec including
* the user agent and timeout. These are hard-coded.
*
* @param $url
*
* @param string $url
* URL to be accessed by the function
* @param $return_to_variable
* Indicates whether the resource accessed by the curl call (HTML page,
@ -80,8 +79,8 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post
* Number of variable sot be posted
* @param $post
* Whether the curl_exec is done as a "get" or a "post"
*
* @return
*
* @return mixed
* an array that consists of three value or NULL if curl is not suported:
* - element 0:
* The value returned from the curl_exec function call.
@ -112,11 +111,15 @@ function do_curl_ext($url, $return_to_variable = TRUE, $number_of_post_vars = 0,
$user_agent = "Mozilla/4.0 pp(compatible; MSIE 5.01; Windows NT 5.0)";
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // allow redirects
curl_setopt($ch, CURLOPT_TIMEOUT, 90); // times out after 90s
// Fail on errors.
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
// Allow redirects.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
// Times out after 90s.
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_to_variable); // return into a variable
// Return into a variable.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_to_variable);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$fedora_user:$fedora_pass");
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
@ -141,7 +144,8 @@ function do_curl_ext($url, $return_to_variable = TRUE, $number_of_post_vars = 0,
/**
* Fedora available
* @return type
*
* @return mixed
*/
function fedora_available() {
@ -151,7 +155,8 @@ function fedora_available() {
/**
* Resource index search available
* @return type
*
* @return mixed
*/
function risearch_available() {
@ -161,7 +166,9 @@ function risearch_available() {
/**
* Returns a UTF-8-encoded transcripiton of the string given in $in_str.
*
* @param string $in_str
*
* @return string A UTF-8 encoded string.
*/
function fix_encoding($in_str) {
@ -176,8 +183,10 @@ function fix_encoding($in_str) {
/**
* valid pid ??
*
* @param type $pid
* @return boolean
*
* @return boolean
*/
function valid_pid($pid) {
$valid = FALSE;
@ -190,8 +199,10 @@ function valid_pid($pid) {
/**
* Valid Dsid ??
*
* @param type $dsid
* @return boolean
*
* @return boolean
*/
function valid_dsid($dsid) {
$valid = FALSE;
@ -204,8 +215,10 @@ function valid_dsid($dsid) {
/**
* fixDsid ??
*
* @param type $dsid
* @return string
*
* @return string
*/
function fix_dsid($dsid) {
$new_dsid = trim($dsid);
@ -214,14 +227,17 @@ function fix_dsid($dsid) {
$replace = '';
$new_dsid = preg_replace($find, $replace, $new_dsid);
if (strlen($new_dsid) > 63)
if (strlen($new_dsid) > 63) {
$new_dsid = substr($new_dsid, -63);
}
if (preg_match('/^[^a-zA-Z]/', $dsid))
if (preg_match('/^[^a-zA-Z]/', $dsid)) {
$new_dsid = 'x' . $new_dsid;
}
if (strlen($new_dsid) == 0)
if (strlen($new_dsid) == 0) {
$new_dsid = 'item' . rand(1, 100);
}
return $new_dsid;
}
@ -229,9 +245,8 @@ function fix_dsid($dsid) {
/**
* Function: get_collections_as_option_array
*
* Description: Returns an associative array of all collection objects in Fedora instance
*
* @return array
* Returns an associative array of all collection objects in Fedora instance
*/
function get_collections_as_option_array() {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
@ -244,7 +259,7 @@ function get_collections_as_option_array() {
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$options = array(
'type' => 'tuples',
'flush' => 'TRUE',
@ -254,9 +269,9 @@ function get_collections_as_option_array() {
'stream' => 'on',
'query' => $query,
);
//The url function will take care of URL encoding...
// The url function will take care of URL encoding.
$content = do_curl(url($url, array('query' => $options)));
$list = explode("\n", $content);
array_shift($list);
$list = preg_replace('/info:fedora\//', '', $list);
@ -264,7 +279,8 @@ function get_collections_as_option_array() {
$trimmed_names[] = trim($namespace);
}
$options = array();
foreach ($list as $item) { //removes blanks
// Removes blanks.
foreach ($list as $item) {
if ($item) {
$parts = explode(',', $item);
$namespace = explode(':', $parts[0]);
@ -283,46 +299,75 @@ function get_collections_as_option_array() {
/**
* Function: get_content_models_as_option_array
*
* Description: Returns an associative array of all available content models in Fedora instance
*
* @return array
* associative array of all available content models in Fedora instance
*/
function get_content_models_as_option_array() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$restricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:');
$namespaces = explode(':', $allowed_string);
foreach ($namespaces as $namespace) {
if ($namespace) {
$allowed[] = trim($namespace);
}
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$restricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:');
$namespaces = explode(':', $allowed_string);
foreach ($namespaces as $namespace) {
if ($namespace) {
$allowed[] = trim($namespace);
}
$query = 'select $object $title from <#ri>
where ($object <fedora-model:label> $title
and ($object <fedora-model:hasModel> <info:fedora/fedora-system:ContentModel-3.0>
or $object <fedora-rels-ext:isMemberOfCollection> <info:fedora/islandora:ContentModelsCollection>)
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query=";
$content = do_curl($url . htmlentities(urlencode($query)));
$list = explode("\n", $content);
array_shift($list);
$list = preg_replace('/info:fedora\//', '', $list);
foreach ($list as $item) { //removes blanks
if ($item) {
$parts = explode(',', $item);
$nameparts = explode(':', $parts[0]);
if (!$restricted || in_array($nameparts[0], $allowed)) {
if (!preg_match('/fedora-system/', $nameparts[0])) {
$options[$parts[0]] = $parts[1] . ' ~ ' . $parts[0];
}
}
}
$query = 'select $object $title from <#ri>
where ($object <fedora-model:label> $title
and ($object <fedora-model:hasModel> <info:fedora/fedora-system:ContentModel-3.0>
or $object <fedora-rels-ext:isMemberOfCollection> <info:fedora/islandora:ContentModelsCollection>)
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by $title';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query=";
$content = do_curl($url . htmlentities(urlencode($query)));
$list = explode("\n", $content);
array_shift($list);
$list = preg_replace('/info:fedora\//', '', $list);
// Removes blanks.
foreach ($list as $item) {
if ($item) {
$parts = explode(',', $item);
$nameparts = explode(':', $parts[0]);
if (!$restricted || in_array($nameparts[0], $allowed)) {
if (!preg_match('/fedora-system/', $nameparts[0])) {
$options[$parts[0]] = $parts[1] . ' ~ ' . $parts[0];
}
}
}
}
return $options;
}
return $options;
}
/**
* This function will retrieve the collections that the given PID belongs to.
*
* @param string $PID
* The PID to find the parents of.
*
* @return array
* $object_PIDs the list of PIDs of the collections that the
* indicated object is a member of.
*/
function get_parent_collections_from_pid($PID) {
$query_string = 'select $parent from <#ri>
where ($object <fedora-rels-ext:isMemberOf> $parent
or $object <fedora-rels-ext:isMemberOfCollection> $parent)
and $object <dc:identifier> \'' . $PID . '\'
order by $object';
$query_string = htmlentities(urlencode($query_string));
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= '?type=tuples&flush=true&format=csv&limit=13000&lang=itql&stream=on&query=' . $query_string;
$content = do_curl($url, TRUE);
$results = explode("\n", $content);
$object_PIDs = preg_replace('/^info:fedora\/|"parent"| /', '', $results);
$object_PIDs = array_values(array_filter($object_PIDs));
return $object_PIDs;
}

116
fedora_repository.module

@ -40,8 +40,10 @@ function fedora_repository_help($path, $arg) {
/**
* fedora repository purge object
*
* @param type $pid
* @param type $name
*
* @return type
*/
function fedora_repository_purge_object($pid = NULL, $name = NULL) {
@ -64,9 +66,11 @@ function fedora_repository_purge_object($pid = NULL, $name = NULL) {
/**
* fedora repository ingest object
*
* @param type $collection_pid
* @param type $collection_label
* @param type $content_model
*
* @return type
*/
function fedora_repository_ingest_object($collection_pid=NULL, $collection_label = NULL, $content_model = NULL) {
@ -266,11 +270,15 @@ function fedora_repository_ingest_form(&$form_state, $collection_pid, $collectio
/**
* fedora repository purge object form
*
* @global type $base_url
*
* @param type $form_state
* @param type $pid
* @param type $referrer
* @return type
*
* @return mixed
* NULL or the form array.
*/
function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NULL) {
global $base_url;
@ -282,7 +290,7 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL
}
$form['pid'] = array(
'#type' => 'hidden',
'#value' => "$pid"
'#value' => "$pid",
);
if (!strstr(drupal_get_destination(), urlencode('fedora/repository'))) {
$form['referrer'] = array(
@ -291,27 +299,26 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL
);
}
if (!isset($form_state['storage']['confirm'])) {
// do your normal $form definition here
// Do your normal $form definition here.
$form['submit'] = array(
'#type' => 'image_button',
'#src' => drupal_get_path('module', 'fedora_repository') . '/images/purge_big.png',
'#value' => t('Purge'),
'#suffix' => 'Purge this object',
);
if (!empty($collectionPid)) {
$collectionPid = $_SESSION['fedora_collection'];
}
//$form['#rebuild'] = $false;
return $form;
}
else {
// ALSO do $form definition here. Your final submit handler (after user clicks Yes, I Confirm) will only see $form_state info defined here. Form you create here passed as param1 to confirm_form
/* ALSO do $form definition here. Your final submit handler
* (after user clicks Yes, I Confirm)
* will only see $form_state info defined here.
* Form you create here passed as param1 to confirm_form*/
return confirm_form($form, 'Confirm Purge Object', $referrer, 'Are you sure you want to delete this object? This action cannot be undone.', 'Delete', 'Cancel'); //Had better luck leaving off last param 'name'
// Had better luck leaving off last param 'name'.
return confirm_form($form, 'Confirm Purge Object', $referrer, 'Are you sure you want to delete this object? This action cannot be undone.', 'Delete', 'Cancel');
}
return $form;
}
@ -487,18 +494,26 @@ function fedora_repository_purge_stream($pid = NULL, $dsId = NULL, $name = NULL)
return $output;
}
/**
* Validates the purge object form.
*
* @param array $form
* The form to validate.
* @param array $form_state
* The state of the form to validate
*/
function fedora_repository_purge_object_form_validate($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_collection');
$pid = $form_state['values']['pid'];
$objectHelper = new ObjectHelper();
$contentModels = $objectHelper->get_content_models_list($pid);
foreach ($contentModels as $contentModel) {
if ($contentModel->pid == 'islandora:collectionCModel') {
$object_helper = new ObjectHelper();
$content_models = $object_helper->get_content_models_list($pid);
foreach ($content_models as $content_model) {
if ($content_model->pid == 'islandora:collectionCModel') {
$member_pids = get_related_items_as_array($pid, 'isMemberOfCollection');
if (is_array($member_pids) && ! empty($member_pids)) {
form_set_error('new_collection_pid', t("Please purge all members of this collection before deleting the collection itself."));
return;
form_set_error('new_collection_pid', t("Please purge all members of this collection before deleting the collection itself."));
return;
}
}
}
@ -506,27 +521,37 @@ function fedora_repository_purge_object_form_validate($form, &$form_state) {
/**
* fedora repository purge object form submit
*
* @param type $form
* The submited form.
* @param type $form_state
* @return type
* The state of the submitted form.
*/
function fedora_repository_purge_object_form_submit($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$pid = $form_state['values']['pid'];
$parents = get_parent_collections_from_pid($pid);
if (!isset($form_state['storage']['confirm'])) {
$form_state['storage']['confirm'] = TRUE; // this will cause the form to be rebuilt, entering the confirm part of the form
$form_state['rebuild'] = TRUE; // along with this
/* This will cause the form to be rebuilt,
* entering the confirm part of the form.*/
$form_state['storage']['confirm'] = TRUE;
// Along with this.
$form_state['rebuild'] = TRUE;
}
else {
// this is where you do your processing after they have pressed the confirm button
/* This is where you do your processing after
* they have pressed the confirm button.*/
$params = array(
"pid" => $pid,
"logMessage" => "Purged",
"force" => ""
"force" => "",
);
try {
$soapHelper = new ConnectionHelper();
$client = $soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M'));
$soap_helper = new ConnectionHelper();
$client = $soap_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M'));
$object = $client->__soapCall('purgeObject', array($params));
unset($form_state['storage']['confirm']);
} catch (exception $e) {
@ -538,39 +563,33 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) {
}
return;
}
if (!empty($form_state['values']['referrer'])) {
$form_state['redirect'] = $form_state['values']['referrer'];
}
elseif (empty($collectionPid) && !empty($_SESSION['fedora_collection']) && $_SESSION['fedora_collection'] != $pid) {
$collectionPid = $_SESSION['fedora_collection'];
$form_state['redirect'] = "fedora/repository/$collectionPid/";
}
else {
$form_state['redirect'] = 'fedora/repository/';
}
// Set the form's redirect to its first identifiable parent collection.
$form_state['redirect'] = "fedora/repository/$parents[0]/";
}
}
/**
* fedora repository purge stream form
*
* @param type $form_state
* @param type $pid
* @param type $dsId
*
* @return type
*/
function fedora_repository_purge_stream_form(&$form_state, $pid, $dsId) {
$form['pid'] = array(
'#type' => 'hidden',
'#value' => "$pid"
'#value' => "$pid",
);
$form['dsid'] = array(
'#type' => 'hidden',
'#value' => "$dsId"
'#value' => "$dsId",
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Purge')
'#value' => t('Purge'),
);
return $form;
@ -578,7 +597,9 @@ function fedora_repository_purge_stream_form(&$form_state, $pid, $dsId) {
/**
* fedora repository purge stream form submit
*
* @global type $base_url
*
* @param type $form
* @param array $form_state
*/
@ -596,6 +617,13 @@ function fedora_repository_purge_stream_form_submit($form, &$form_state) {
$form_state['redirect'] = "fedora/repository/$pid";
}
/**
*
* @param unknown_type $form_state
* @param unknown_type $pid
* @param unknown_type $dsid
* @param unknown_type $label
*/
function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $label) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$form = array(
@ -621,7 +649,7 @@ function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $
if (count($version_array) > 1) {
$form['#attributes'] = array(
'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;'
'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;',
);
$form['version'] = array(
'#type' => 'select',
@ -635,11 +663,13 @@ function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $
/**
* fedora repository replace stream
*
* @param type $pid
* @param type $dsId
* @param type $dsLabel
* @param type $collectionName
* @return type
*
* @return string
*/
function fedora_repository_replace_stream($pid, $dsId, $dsLabel = '', $collectionName = NULL) {
if ($pid == NULL || $dsId == NULL) {
@ -653,10 +683,12 @@ function fedora_repository_replace_stream($pid, $dsId, $dsLabel = '', $collectio
/**
* fedora repository replace stream form
*
* @param type $form_state
* @param type $pid
* @param type $dsId
* @param type $dsLabel
*
* @return type
*/
function fedora_repository_replace_stream_form(&$form_state, $pid, $dsId, $dsLabel) {
@ -675,7 +707,7 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) {
// If a file was uploaded, process it.
if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['file'])) {
// attempt to save the uploaded file
// Attempt to save the uploaded file.
$file = file_save_upload('file', array(), file_directory_path());
// set error is file was not uploaded
@ -843,7 +875,8 @@ function fedora_repository_edit_qdc_form_submit($form, &$form_state) {
$soap_helper = new ConnectionHelper();
$client = $soap_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M'));
// Check the content model for a custom edit metadata form submit function.
/* Check the content model for a custom
* edit metadata form submit function.*/
if (isset($form_state['values']['pid'])) {
module_load_include('inc', 'fedora_repository', 'ContentModel');
if (($cm = ContentModel::loadFromObject($form_state['values']['pid'])) !== FALSE) {
@ -2247,6 +2280,7 @@ function fedora_repository_display_schema($file) {
*/
function fedora_repository_batch_reingest_object($object, $module_name, &$context) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');

Loading…
Cancel
Save