Follow-up issue from #721082: Prevent conflicting namespaces and move hook_rdf_namespaces() invocation into rdf.module. Contrib RDF should check whether there are conflicting namespaces which are silently ignored by core (by design). I don't think we should check this systematically on every page load, but only in admin pages and in Status report (admin/reports/status). hook_requirements is our friend.

Comments

mlncn’s picture

Issue tags: +RDF

Tagging as RDF.

adorsk’s picture

Project: Resource Description Framework (RDF) » RDF Extensions
Component: Settings » Code
Status: Active » Needs review
StatusFileSize
new4.77 KB

Here is a patch that adds a warning to the status page (/admin/reports/status) , and displays conflicting namespaces on the RDF settings page ( /admin/config/services/rdf/namespaces ).

Please note that that this is just a first draft. The display on the RDF settings page should probably be redesigned after namespace CRUD operations are added ( http://drupal.org/node/1117646 ).

scor’s picture

Status: Needs review » Needs work

Thanks adorsk for this patch! Please download the Dreditor tool to review your patch above, it will highlight several issues with regards to Drupal's coding standards (tabs should be 2 spaces, and there should be no trailing space).

+++ b/rdfx.admin.inc
@@ -13,13 +13,68 @@ function rdfx_mapping_overview() {
+    // Display a warning message.
+    $output .= '<div style="color: red;">' . t("Warning: The following namespaces have conflicts:") . '</div>';

we should move this style into a css file for rdfx

Also, there is some duplicated code in rdfx_requirements(), this could possibly be moved into the same function.

adorsk’s picture

Status: Needs work » Needs review
StatusFileSize
new10.13 KB

Roger that scor, here's a revised patch.

Changes:

1. It should be now be compliant with Drupal's coding standards.
2. It uses the standard drupal error message class pair 'messages error' for displaying the warning message on the rdfx namespaces page

I did notice the similar code chunks in rdfx.module/rdfx_requirements and rdfx.admin.inc/rdfx_admin_namespaces . However, they're not doing exactly the same thing...one filters namespaces into two groups, the other just checks if there is a namespace conflict.

I prefer to leave this as-is for now, but let me know what you think.

scor’s picture

Status: Needs review » Needs work

Looking much better Alex!

+++ b/rdfx.admin.inc
@@ -13,13 +13,68 @@ function rdfx_mapping_overview() {
+    // Uri should be an array.
+    if (is_array($uri)) {

It's only an array if there are potential duplicates. The comment should say something like "$uri will be an array if there are duplicate namespaces for the prefix"

+++ b/rdfx.admin.inc
@@ -13,13 +13,68 @@ function rdfx_mapping_overview() {
+      // If the array has just one uri then the namespace is unique.
+      if (count($unique_uris) == 1) {
+        $unique_namespaces[$prefix] = $unique_uris[0];
+      }

I would not include the unique URIs in this logic, and leave the unique URI table as it currently is in RDFx which calls the core rdf_get_namespace() API function. This patch should just add an extra table for the conflicting namespaces, that's it :)

+++ b/rdfx.module
@@ -11,10 +11,10 @@
-}
-else {
-  define('RDF_ARC2_PATH', drupal_get_path('module', 'rdfx') . '/vendor/arc');
-}
+ }
+ else {
+   define('RDF_ARC2_PATH', drupal_get_path('module', 'rdfx') . '/vendor/arc');
+ }

I'm not sure you meant to change these lines... there are plenty of other hunks like this one which change the indentation as well.

+++ b/rdfx.module
@@ -255,13 +255,43 @@ function rdfx_requirements($phase) {
+      // Uri should be an array.
+      if (is_array($uri)) {
+
+        // If there were multiple URIs for one namespace...
+        if (count(array_unique($uri)) > 1) {

That logic is more like what I was suggesting above. And you could have one function to get the conflicting namespaces, and call it here in rdfx_requirements() and when generating the table of conflicting namespaces.

Powered by Dreditor.

adorsk’s picture

Status: Needs work » Needs review
StatusFileSize
new4.3 KB

@scor

Your suggestions above sound good to me. Here's another try:

Changes:

1. Took out irrelevant spacing changes from the patch .
2. Added a function 'rdfx_get_conflicting_namespaces' to rdfx.module .
3. Used that function in rdfx.module/rdfx_requirements and rdfx.admin/namespaces .

scor’s picture

Status: Needs review » Needs work

Ok, last nitpicking and after that it's good to go!

+++ b/rdfx.admin.inc
@@ -8,17 +8,45 @@ function rdfx_mapping_overview() {
+  // Display a label.
+  $output .= '<div class="messages status">' . t("The following namespaces are valid") . ':' . '</div>';

I just tried this patch when I had no conflicting namespaces, and I found this message to be confusing. How about displaying this message only when it makes sense, that is to say only when there are conflicting namespaces?

+++ b/rdfx.module
@@ -255,13 +255,31 @@ function rdfx_requirements($phase) {
+    // Get conflicting namespaces.
+    $conflicting_namespaces = rdfx_get_conflicting_namespaces();
+
+    // If there were any conflicting namespaces...
+    if ($conflicting_namespaces) {

you could spare the $conflicting_namespaces variable here and just call the function in the if statement...

Powered by Dreditor.

adorsk’s picture

No worries, I appreciate the attention to detail.

Let's try this one.

Changes:

1. Valid namespaces label only is shown if there were namespaces with conflicts.

2. Took out unnecessary '$conflicting_namespaces = ' assignment in rdfx_requirements.

adorsk’s picture

Status: Needs work » Needs review

Sorry, forgot to change the issue status.

scor’s picture

Status: Needs review » Needs work
+++ b/rdfx.admin.inc
@@ -8,17 +8,48 @@ function rdfx_mapping_overview() {
+    $output .= '<div class="messages warning">' . t("Warning: The following namespaces have conflicts") . ':' . '</div>';
+    $output .= '<div class="messages status">' . t("The following namespaces do not have conflicts") . ':' . '</div>';

While checking that patch, I found that the ending semi colon ":" looks odd inside a color box with nothing following it in the same color space. (I think it would look better without the :).

+++ b/rdfx.module
@@ -313,6 +313,54 @@ function rdfx_requirements($phase) {
+    if ( rdfx_get_conflicting_namespaces() ) {
+
+      // Add a requirement warning and break.

coding standard. no space inside the if parenthesis. remove newline too to keep code compact.

+++ b/rdfx.module
@@ -313,6 +313,54 @@ function rdfx_requirements($phase) {
+        'severity' => REQUIREMENT_WARNING,

I would rather throw an error here, since the prefixes will not be output anywhere, developers should really be aware of that as early as possible.

+++ b/rdfx.module
@@ -313,6 +313,54 @@ function rdfx_requirements($phase) {
+  // For each namespace...
+  foreach ($rdf_namespaces as $prefix => $uris) {
+
+    // If there are multiple URIs for the prefix...
+    if (is_array($uris)) {
+
+      // Consolidate identical URIs.
+      $consolidated_uris = array_unique($uris);
+
+      // If there were multiple unique URIs,
+      // then add the prefix/URI array to the list of conflicting namespaces.
+      if (count($consolidated_uris) > 1) {
+
+        $conflicting_namespaces[$prefix] = $consolidated_uris;
+      }
+    }
+  }

probably could do with less new lines here.

adorsk’s picture

Here's an update that incorporates the suggestions made in #10.

Changes:

1. Removed the ':'s from the namespace table labels
2. Took out newlines, unnecessary comments.

scor’s picture

Status: Needs work » Fixed

Thanks Alex for your patience! I've committed your patch (see commit on your user profile). http://drupalcode.org/project/rdfx.git/commit/4ca99cf

adorsk’s picture

Sweet! Thanks for your patience as well. I learned quite a bit about the process of making patches and coding standards. Hopefully I'll be able to put this experience into practice with future patches. I appreciate the high standards.

Status: Fixed » Closed (fixed)
Issue tags: -RDF

Automatically closed -- issue fixed for 2 weeks with no activity.