Hi Everyone,
I guess I should preface this by saying that I am brand new on this forum, and really to using Drupal/PHP in general (I come from a Java/Python/Node.js background), so I'm sorry if this has been covered somewhere else. On to my question...
I am helping to design a Drupal site for an academic research project that acts as a service for uploading and reviewing icons used as map symbols. The icons being reviewed are stored on a separate server and accessed/updated via an API we have defined. Icons are uploaded to the remote service site as Esri Style Files (I'm sorry I don't have documentation on this file type, Esri doesn't supply any) and we use other Esri products to convert these style files into PNGs and SVGs, as well as display them on a map in a client that lets a user download the icons stored on our system. Simply put, we have a service that provides data two two clients: an existing read-only client for the public, and a new read-write client for moderator type folks. Honestly, I have some pretty serious doubts as to whether or not this is an appropriate use of Drupal, if it isn't please let me know.
Right now, I am trying to add the component that will enable moderators to upload new icons. As it stands, we have a content type, Upload Symbol, accessed from Add Content that users can add metadata and attach a Style File for uploading to the remote service. I have a rule set up that executes custom PHP code to upload the information to the remote service when a node of content type Upload Symbol is added or updated. This rule uses executes following code and logs it's process using dblog_watchdog() (unfortunately this project is not public right now so I have to leave out the meaty bits).
<?php
$styleUploadRequest = # new POST request
$serviceRequest = # new GET request
try {
# ---- Uploading the Style File ----
if (!$styleUploadRequest->addPostFile(# stuff)) {
dblog_watchdog(new array('message' => 'Unable to append the POST files to the HTTP request.', 'severity' => 6));
return;
}
$styleUploadResponse = $styleUploadRequest->send();
if ($styleUploadResponse->getResponseCode() != 200) {
dblog_watchdog(new array('message' => 'Upload returned an bad response.'));
return;
}
# ---- Processing the Style File ----
# Some processing
if (!$serviceRequest->addPostFields(# stuff))) {
dblog_watchdog(new array('message' => 'Unable to append the POST fields to the HTTP request.', 'severity' => 6));
return;
}
$serviceResponse = $serviceRequest->send();
if ($serviceResponse->getResponseCode() != 200) {
dblog_watchdog(new array('message' => 'Processing returned a bad response.', 'severity' => 6));
return;
}
dblog_watchdog(new array('message' => $serviceResponse->getBody(), 'severity' => 6));
} catch (HttpException $e) {
dblog_watchdog(new array('message' => 'HTTP Exception encountered when uploading a file:\n' . $e, 'severity' => 6));
}
?>I realize updating these changes is a two step process and I hate it, but it's what they are making me use because... yeah I've got nothing here. Anyway, the calls to dblog_watchdog() aren't being logged in the system. I'm trying to figure out if this is an issue with how I have my rule set up (as in the rule is never firing) or if I'm calling dblog_watchdog() improperly. Any help you an provide is greatly appreciated, even if that help is telling me I[m an idiot and that we shouldn't be doing this sort of thing with Drupal. Some simple tips on best practices for debugging Drupal would be great as well.
Thanks in advance!
Ryan Mullins
Comments
You should be calling
You should be calling watchdog(), e.g., the last one:
watchdog('my rule', 'HTTP Exception encountered when uploading a file: %exception', array('%exception' => $e), WATCHDOG_NOTICE);Notes:
watchdog()is the general function for logging an event,dblog_watchdog()is responsible for routing it to the dblog;"HTTP Exception encountered when uploading a file:\n%exception"Thanks
That worked well. Much appreciated.