Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

ISLANDORA-581 On content model trigered tabs we use module_exists to …

…verify if a module is present and enabled before calling code. We also use module_load_include instead of including directly.
  • Loading branch information...
commit 8c3da4569a6f271dd5713cb435621358fa40ece8 1 parent 1fa2f2a
William Panting authored June 22, 2012

Showing 1 changed file with 77 additions and 66 deletions. Show diff stats Hide diff stats

  1. 143  ContentModel.inc
143  ContentModel.inc
... ...
@@ -1,11 +1,11 @@
1 1
 <?php
2 2
 
3 3
 /**
4  
- * @file 
5  
- * 
  4
+ * @file
  5
+ *
6 6
  */
7 7
 /**
8  
- * @file 
  8
+ * @file
9 9
  * Content Model Class
10 10
  */
11 11
 module_load_include('inc', 'fedora_repository', 'XMLDatastream');
@@ -56,7 +56,7 @@ class ContentModel extends XMLDatastream {
56 56
   }
57 57
 
58 58
   /**
59  
-   * Ingests a Content Model from a file to the specified pid/dsid . 
  59
+   * Ingests a Content Model from a file to the specified pid/dsid .
60 60
    * Returns FALSE on failure.
61 61
    *
62 62
    * @param string $pid
@@ -83,7 +83,7 @@ class ContentModel extends XMLDatastream {
83 83
   }
84 84
 
85 85
   /**
86  
-   * Ingests a Content Model from an existing model to the specified pid/dsid . 
  86
+   * Ingests a Content Model from an existing model to the specified pid/dsid .
87 87
    * Returns FALSE on failure.
88 88
    *
89 89
    * @param string $pid
@@ -112,7 +112,7 @@ class ContentModel extends XMLDatastream {
112 112
   }
113 113
 
114 114
   /**
115  
-   * Ingests a minimum Content Model to the specified pid/dsid. 
  115
+   * Ingests a minimum Content Model to the specified pid/dsid.
116 116
    * Returns FALSE on failure.
117 117
    *
118 118
    * @param string $pid
@@ -515,7 +515,7 @@ class ContentModel extends XMLDatastream {
515 515
    * in the form builder if more complex forms or behaviour is required.
516 516
    * Each element has the following keys: 'label', 'type', 'required', 'description', and if defined, 'authoritative_list' and/or 'parameters'
517 517
    *
518  
-   * @return string[] $elements 
  518
+   * @return string[] $elements
519 519
    */
520 520
   public function getIngestFormElements() {
521 521
     $ret = FALSE;
@@ -575,14 +575,14 @@ class ContentModel extends XMLDatastream {
575 575
   }
576 576
 
577 577
   /**
578  
-   * Decrements an ingest form element in the list of elements.  
  578
+   * Decrements an ingest form element in the list of elements.
579 579
    * Updates the "order".  This method is simply an overload to the incIngestFormElement
580 580
    * which has a direction parameter.
581 581
    *
582  
-   * TODO: Might be useful to move multiple places at once, or define 
583  
-   * a method to move to an absolute position.  
  582
+   * TODO: Might be useful to move multiple places at once, or define
  583
+   * a method to move to an absolute position.
584 584
    *
585  
-   * @param String $name 
  585
+   * @param String $name
586 586
    * @return boolean $success
587 587
    */
588 588
   public function decIngestFormElement($name) {
@@ -590,14 +590,14 @@ class ContentModel extends XMLDatastream {
590 590
   }
591 591
 
592 592
   /**
593  
-   * Increments (or decrements) ingest form element in the list of elements.  
  593
+   * Increments (or decrements) ingest form element in the list of elements.
594 594
    * Updates the "order".  The $reorder parameter accepts 'inc' or 'dec' to
595 595
    * specify the direction to move (defaults to increment.)
596 596
    *
597  
-   * TODO: Might be useful to move multiple places at once, or define 
598  
-   * a method to move to an absolute position.  
  597
+   * TODO: Might be useful to move multiple places at once, or define
  598
+   * a method to move to an absolute position.
599 599
    *
600  
-   * @param String $name 
  600
+   * @param String $name
601 601
    * @param String $reorder
602 602
    * @return boolean $success
603 603
    */
@@ -658,7 +658,7 @@ class ContentModel extends XMLDatastream {
658 658
   /**
659 659
    * Sets a parameter of an ingest form element.  If the value of the element is FALSE the parameter
660 660
    * will be removed entirely (if you want to store FALSE as a value, then send the String "FALSE").
661  
-   * 
  661
+   *
662 662
    * @param String $elementName
663 663
    * @param String $paramName
664 664
    * @param String $paramValue
@@ -729,7 +729,7 @@ class ContentModel extends XMLDatastream {
729 729
 
730 730
   /**
731 731
    * Gets a list of all parameters that belong to the specified ingest form element.
732  
-   * 
  732
+   *
733 733
    * @param String $elementName
734 734
    * @return boolean success
735 735
    */
@@ -762,7 +762,7 @@ class ContentModel extends XMLDatastream {
762 762
   }
763 763
 
764 764
   /**
765  
-   * Edits the ingest form element specified. 
  765
+   * Edits the ingest form element specified.
766 766
    * NOTE: The element name can not be changed.  To update an elements name
767 767
    * it must be deleted and added with the new name.
768 768
    *
@@ -854,12 +854,12 @@ class ContentModel extends XMLDatastream {
854 854
   }
855 855
 
856 856
   /**
857  
-   * Decrements an authority list item from a form element in the list of elements.  
  857
+   * Decrements an authority list item from a form element in the list of elements.
858 858
    * Updates the "order".  This method is simply an overload to the incAuthListItem
859 859
    * which has a direction parameter.
860 860
 
861 861
    *
862  
-   * @param String $elementName 
  862
+   * @param String $elementName
863 863
    * @param String $value
864 864
    * @return boolean $success
865 865
    */
@@ -868,10 +868,10 @@ class ContentModel extends XMLDatastream {
868 868
   }
869 869
 
870 870
   /**
871  
-   * Increments (or decrements) an authority list item from a form element in the list of elements.  
872  
-   * Updates the "order".  
  871
+   * Increments (or decrements) an authority list item from a form element in the list of elements.
  872
+   * Updates the "order".
873 873
    *
874  
-   * @param String $elementName 
  874
+   * @param String $elementName
875 875
    * @param String $value
876 876
    * @param String $direction
877 877
    * @return boolean $success
@@ -921,7 +921,7 @@ class ContentModel extends XMLDatastream {
921 921
   }
922 922
 
923 923
   /**
924  
-   * Removes an authority list item from a form element.  
  924
+   * Removes an authority list item from a form element.
925 925
    * @param String $elementName
926 926
    * @param String $value
927 927
    * @return boolean $success
@@ -966,7 +966,7 @@ class ContentModel extends XMLDatastream {
966 966
   }
967 967
 
968 968
   /**
969  
-   * Adds an authority list item to a form element.  
  969
+   * Adds an authority list item to a form element.
970 970
    * @param String $elementName
971 971
    * @param String $value
972 972
    * @param String $label (optional)
@@ -1310,9 +1310,9 @@ class ContentModel extends XMLDatastream {
1310 1310
 
1311 1311
   /**
1312 1312
    * Executes the ingest rules that apply to the specified file/mimetype.
1313  
-   * Returns FALSE on failure. 
1314  
-   * 
1315  
-   * If $preview is TRUE, then only execute rules with 
  1313
+   * Returns FALSE on failure.
  1314
+   *
  1315
+   * If $preview is TRUE, then only execute rules with
1316 1316
    * a parameter 'preview'.  Used to generate previews for the file chooser.
1317 1317
    *
1318 1318
    * @param string $file
@@ -1475,19 +1475,30 @@ class ContentModel extends XMLDatastream {
1475 1475
                 self::$errors[] = 'Execute Form Handler: file \'' . $path . '\' does not exist.';
1476 1476
               }
1477 1477
               else {
1478  
-                require_once($path);
1479  
-                $className = $method->getAttribute('class');
1480  
-                $methodName = ($method->getAttribute('method'));
1481  
-                if (!class_exists($className)) {
1482  
-                  self::$errors[] = 'Execute Form Handler: class \'' . $className . '\' does not exist.';
1483  
-                }
1484  
-                else {
1485  
-                  $class = new $className($pid);
1486  
-                  if (!method_exists($class, $methodName)) {
1487  
-                    self::$errors[] = 'Execute Form Handler: method \'' . $className . '->' . $methodName . '\' does not exist.';
  1478
+
  1479
+                $file_extension = pathinfo($method->getAttribute('file'), PATHINFO_EXTENSION);
  1480
+                $file_path_without_extension = $method->getAttribute('file');
  1481
+                /* Only in PHP. This is meant to avoid file path
  1482
+                 * concatenation issues.*/
  1483
+                $file_path_without_extension = substr($file_path_without_extension, 0, strlen($file_path_without_extension) - (strlen($file_extension) + 1));
  1484
+                /* Only try to execute if the module is present, this is
  1485
+                 * necessarybecause we go outside of the expected
  1486
+                 * 'Drupal Way' and have dynamic dependencies.*/
  1487
+                if (module_exists(!empty($module) ? $module : 'fedora_repository')) {
  1488
+                  module_load_include($file_extension, !empty($module) ? $module : 'fedora_repository', $file_path_without_extension);
  1489
+                  $className = $method->getAttribute('class');
  1490
+                  $methodName = ($method->getAttribute('method'));
  1491
+                  if (!class_exists($className)) {
  1492
+                    self::$errors[] = 'Execute Form Handler: class \'' . $className . '\' does not exist.';
1488 1493
                   }
1489 1494
                   else {
1490  
-                    $output = $class->$methodName($page_number);
  1495
+                    $class = new $className($pid);
  1496
+                    if (!method_exists($class, $methodName)) {
  1497
+                      self::$errors[] = 'Execute Form Handler: method \'' . $className . '->' . $methodName . '\' does not exist.';
  1498
+                    }
  1499
+                    else {
  1500
+                      $output = $class->$methodName($page_number);
  1501
+                    }
1491 1502
                   }
1492 1503
                 }
1493 1504
               }
@@ -1527,8 +1538,8 @@ class ContentModel extends XMLDatastream {
1527 1538
   }
1528 1539
 
1529 1540
   /**
1530  
-   * Adds an allowed mimetype to the model. 
1531  
-   * 
  1541
+   * Adds an allowed mimetype to the model.
  1542
+   *
1532 1543
    * @param String $type
1533 1544
    * @return boolean $success
1534 1545
    */
@@ -1581,7 +1592,7 @@ class ContentModel extends XMLDatastream {
1581 1592
   /**
1582 1593
    * getDisplayMethods ??
1583 1594
    * @param type $ds
1584  
-   * @return type 
  1595
+   * @return type
1585 1596
    */
1586 1597
   public function getDisplayMethods($ds) {
1587 1598
     $ret = FALSE;
@@ -1603,7 +1614,7 @@ class ContentModel extends XMLDatastream {
1603 1614
    * addDs ??
1604 1615
    * @param type $dsid
1605 1616
    * @param type $display_in_fieldset
1606  
-   * @return boolean 
  1617
+   * @return boolean
1607 1618
    */
1608 1619
   public function addDs($dsid, $display_in_fieldset = FALSE) {
1609 1620
     $ret = FALSE;
@@ -1632,7 +1643,7 @@ class ContentModel extends XMLDatastream {
1632 1643
   /**
1633 1644
    * removeDs ??
1634 1645
    * @param type $dsid
1635  
-   * @return boolean 
  1646
+   * @return boolean
1636 1647
    */
1637 1648
   public function removeDs($dsid) {
1638 1649
     $ret = FALSE;
@@ -1648,7 +1659,7 @@ class ContentModel extends XMLDatastream {
1648 1659
   /**
1649 1660
    * displayInFieldset ??
1650 1661
    * @param type $dsid
1651  
-   * @return type 
  1662
+   * @return type
1652 1663
    */
1653 1664
   public function displayInFieldset($dsid) {
1654 1665
     $ret = FALSE;
@@ -1662,7 +1673,7 @@ class ContentModel extends XMLDatastream {
1662 1673
    * setDisplayInFieldset ??
1663 1674
    * @param type $dsid
1664 1675
    * @param type $value
1665  
-   * @return boolean 
  1676
+   * @return boolean
1666 1677
    */
1667 1678
   public function setDisplayInFieldset($dsid, $value = TRUE) {
1668 1679
     $ret = FALSE;
@@ -1686,7 +1697,7 @@ class ContentModel extends XMLDatastream {
1686 1697
    * @param type $file
1687 1698
    * @param type $class
1688 1699
    * @param type $method
1689  
-   * @return boolean 
  1700
+   * @return boolean
1690 1701
    */
1691 1702
   public function setDefaultDispMeth($dsid, $module, $file, $class, $method) {
1692 1703
     $ret = FALSE;
@@ -1725,7 +1736,7 @@ class ContentModel extends XMLDatastream {
1725 1736
    * @param type $file
1726 1737
    * @param type $class
1727 1738
    * @param type $method
1728  
-   * @return boolean 
  1739
+   * @return boolean
1729 1740
    */
1730 1741
   public function removeDispMeth($dsid, $module, $file, $class, $method) {
1731 1742
     $ret = FALSE;
@@ -1757,7 +1768,7 @@ class ContentModel extends XMLDatastream {
1757 1768
    * @param type $class
1758 1769
    * @param type $method
1759 1770
    * @param type $default
1760  
-   * @return boolean 
  1771
+   * @return boolean
1761 1772
    */
1762 1773
   public function addDispMeth($dsid, $module, $file, $class, $method, $default = FALSE) {
1763 1774
     $ret = FALSE;
@@ -1779,7 +1790,7 @@ class ContentModel extends XMLDatastream {
1779 1790
   /**
1780 1791
    * getAddDsMethod ??
1781 1792
    * @param type $ds
1782  
-   * @return type 
  1793
+   * @return type
1783 1794
    */
1784 1795
   public function getAddDsMethod($ds) {
1785 1796
     $ret = FALSE;
@@ -1801,7 +1812,7 @@ class ContentModel extends XMLDatastream {
1801 1812
   /**
1802 1813
    * getIngestRule ??
1803 1814
    * @param type $rule_id
1804  
-   * @return type 
  1815
+   * @return type
1805 1816
    */
1806 1817
   public function getIngestRule($rule_id) {
1807 1818
     $ret = FALSE;
@@ -1817,7 +1828,7 @@ class ContentModel extends XMLDatastream {
1817 1828
    * removeAppliesTo ??
1818 1829
    * @param type $rule_id
1819 1830
    * @param type $type
1820  
-   * @return boolean 
  1831
+   * @return boolean
1821 1832
    */
1822 1833
   public function removeAppliesTo($rule_id, $type) {
1823 1834
     $ret = FALSE;
@@ -1842,7 +1853,7 @@ class ContentModel extends XMLDatastream {
1842 1853
    * addAppliesTo ??
1843 1854
    * @param type $rule_id
1844 1855
    * @param type $type
1845  
-   * @return boolean 
  1856
+   * @return boolean
1846 1857
    */
1847 1858
   public function addAppliesTo($rule_id, $type) {
1848 1859
     $ret = FALSE;
@@ -1871,7 +1882,7 @@ class ContentModel extends XMLDatastream {
1871 1882
    * @param type $method
1872 1883
    * @param type $dsid
1873 1884
    * @param type $modified_files_ext
1874  
-   * @return boolean 
  1885
+   * @return boolean
1875 1886
    */
1876 1887
   public function addIngestMethod($rule_id, $module, $file, $class, $method, $dsid, $modified_files_ext) {
1877 1888
     $ret = FALSE;
@@ -1898,7 +1909,7 @@ class ContentModel extends XMLDatastream {
1898 1909
    * @param type $file
1899 1910
    * @param type $class
1900 1911
    * @param type $method
1901  
-   * @return boolean 
  1912
+   * @return boolean
1902 1913
    */
1903 1914
   public function removeIngestMethod($rule_id, $module, $file, $class, $method) {
1904 1915
     $ret = FALSE;
@@ -1929,7 +1940,7 @@ class ContentModel extends XMLDatastream {
1929 1940
    * @param type $method
1930 1941
    * @param type $name
1931 1942
    * @param type $value
1932  
-   * @return boolean 
  1943
+   * @return boolean
1933 1944
    */
1934 1945
   public function addIngestMethodParam($rule_id, $module, $file, $class, $method, $name, $value) {
1935 1946
     $ret = FALSE;
@@ -1981,7 +1992,7 @@ class ContentModel extends XMLDatastream {
1981 1992
    * @param type $class
1982 1993
    * @param type $method
1983 1994
    * @param type $name
1984  
-   * @return boolean 
  1995
+   * @return boolean
1985 1996
    */
1986 1997
   public function removeIngestMethodParam($rule_id, $module, $file, $class, $method, $name) {
1987 1998
     $ret = FALSE;
@@ -2024,7 +2035,7 @@ class ContentModel extends XMLDatastream {
2024 2035
   /**
2025 2036
    * removeIngestRule ??
2026 2037
    * @param type $rule_id
2027  
-   * @return type 
  2038
+   * @return type
2028 2039
    */
2029 2040
   public function removeIngestRule($rule_id) {
2030 2041
     $ret = FALSE;
@@ -2043,7 +2054,7 @@ class ContentModel extends XMLDatastream {
2043 2054
    * @param type $method
2044 2055
    * @param type $dsid
2045 2056
    * @param type $modified_files_ext
2046  
-   * @return type 
  2057
+   * @return type
2047 2058
    */
2048 2059
   public function addIngestRule($applies_to, $module, $file, $class, $method, $dsid, $modified_files_ext) {
2049 2060
     $ret = FALSE;
@@ -2061,7 +2072,7 @@ class ContentModel extends XMLDatastream {
2061 2072
 
2062 2073
   /**
2063 2074
    * getIngestRules ??
2064  
-   * @return type 
  2075
+   * @return type
2065 2076
    */
2066 2077
   public function getIngestRules() {
2067 2078
     $ret = FALSE;
@@ -2105,7 +2116,7 @@ class ContentModel extends XMLDatastream {
2105 2116
 
2106 2117
   /**
2107 2118
    * getIngestFormAttributes ??
2108  
-   * @return type 
  2119
+   * @return type
2109 2120
    */
2110 2121
   public function getIngestFormAttributes() {
2111 2122
     $ret = FALSE;
@@ -2125,7 +2136,7 @@ class ContentModel extends XMLDatastream {
2125 2136
    * @param type $page
2126 2137
    * @param type $hide_file_chooser
2127 2138
    * @param type $redirect
2128  
-   * @return boolean 
  2139
+   * @return boolean
2129 2140
    */
2130 2141
   public function editIngestFormAttributes($dsid, $page, $hide_file_chooser = FALSE, $redirect = TRUE) {
2131 2142
     $ret = FALSE;
@@ -2152,7 +2163,7 @@ class ContentModel extends XMLDatastream {
2152 2163
 
2153 2164
   /**
2154 2165
    * getIngestFormBuilderMethod
2155  
-   * @return type 
  2166
+   * @return type
2156 2167
    */
2157 2168
   public function getIngestFormBuilderMethod() {
2158 2169
     $ret = FALSE;
@@ -2174,7 +2185,7 @@ class ContentModel extends XMLDatastream {
2174 2185
    * @param type $class
2175 2186
    * @param type $method
2176 2187
    * @param type $handler
2177  
-   * @return boolean 
  2188
+   * @return boolean
2178 2189
    */
2179 2190
   public function editIngestFormBuilderMethod($module, $file, $class, $method, $handler) {
2180 2191
     $ret = FALSE;
@@ -2192,7 +2203,7 @@ class ContentModel extends XMLDatastream {
2192 2203
 
2193 2204
   /**
2194 2205
    * Find the form element with name $name.
2195  
-   * 
  2206
+   *
2196 2207
    * @param string $name
2197 2208
    *   The name of the form element to find.
2198 2209
    * @return DOMElement
@@ -2263,7 +2274,7 @@ class ContentModel extends XMLDatastream {
2263 2274
    *
2264 2275
    * @param string $name
2265 2276
    *   Name of the form to remove.
2266  
-   * 
  2277
+   *
2267 2278
    * @return boolean
2268 2279
    *   TRUE on success, FALSE otherwise.
2269 2280
    */

0 notes on commit 8c3da45

Please sign in to comment.
Something went wrong with that request. Please try again.