Recent Entries 7
- pattern minor 112d agoModule for sending messages through PubNubI have created a Drupal 6 module that sends messages through PubNub when the user updates information about a Node. I have a separate app that, when launched, calls my Drupal site and receives a JSON array containing a lot of information about some nodes. I then update the info in my other app by PubNub->publish from Drupal every time the page is reloaded after the Node is updated. I have the following in my `foo.module` file: hook_admin: //not really a hook ``` function moduleName_admin(){ //Here we are pulling in the Pubnub.php file from the module directory // NOTE: This file requires PubnubAES.php even when you aren't using encryption so include it too module_load_include('php', 'moduleName', 'Pubnub'); $pubnub = new Pubnub( "PUBKEY", "SUBKEY", "", false ); $form = array(); $query = "SELECT info FROM tables;" $results = db_query($query); while($r=db_fetch_object($results)){ $form['moduleName_fieldDescription_'.$r->nid] = array( '#type' => 'radios', '#title' => "Select one for ".$r->info.":", '#options' => array( t('Foo'), t('Bar'), t('Baz') ), '#default_value' => variable_get('moduleName_fieldDescription_'.$r->nid, '0'), ); $pubnub->publish(array( 'channel' => 'channelName', 'message' => array("id"=>$r->nid, "selected"=>variable_get('moduleName_fieldDescription_'.$r->nid, '0')) )); } return system_settings_form($form); } ``` JSON page: ``` function moduleName_JSON(){ $query = "SELECT info FROM table;" $results = db_query($query); $infoObject = array(); for($i=0;$r = db_fetch_object($results); $i++){ $infoObject[$i] = array( 'info' => $r->info, 'id' => $r->nid, 'selected' => variable_get('moduleName_fieldDescription_'.$r->nid, '0'), ); } //This next part will wrap the JSON in a function so jQuery can be called like //$.ajax( { //url:"example.com/moduleName/json", //dataType: 'jsonp', //callback: 'fo
- pattern minor 112d agoDrupal: Placing Code (PHP) within the Drupal System (as well as css)I have a node template that grabs fields from a content type. In the node--[contenttype].tpl.php file I have two sections (The second is html/php and grabs variables from the first section or from the content type and simply displayed it). The first is strictly php and does three things: - Grabs numbers from one of the content type fields and rearranges them according to some criteria. Setting this output as a variable to be used later in the page. - Grabs two taxonomy terms and sets them as variables to be used later in the page. Also compares these variables to an array as the key in order to set the value as another variable to be used later in the page. - Creates a function for converting stdClass Objects to Arrays and uses it in one of the above two actions. My question is, should this php even go in the node--[contenttype].tpl.php file? The numbers output and taxonomy output is only ever going to be used in this node (the arrays set for comparison are only relevant with this content type), but the Class function could be used on other pages. I'm not getting how I can leverage the Drupal system in order to get a strong and easily upgradable code base (for going to Drupal 8 in the future). How should my mind be processing executable challenges. Should I be asking certain questions in order to determine if something goes into template.php, into a new module, or where its css goes? Should all that css be going into style.css? Can I break it out somehow? EDIT: Here is my code for node--[contenttype].tpl.php ``` 34, "Curriculum" => 35, "Study Labs" => 36, "Stage Performances" => 37, ); $location_to_nid = array( "Visit Examples" => 38, "We Come To You" => 39); // to array (from stdClass object) // for field_location_category to get name // without it, get white screen of death because ['taxonomy_term'] is an object not array // Credit: http://www.if-not-true-then-false.com/2009/php-tip-convert-stdclass-object-to-multidimensio
- pattern minor 112d agoContinuous delivery workflow: Build script for PHP Composer (Drupal) on DockerI'd like to set up a continuous delivery workflow for our new Drupal site. When someone pushes to our Git repo (typically) master branch, a build job on our CI server is triggered. This job will check out the source code, import the database from production, and build the Drupal project running in a Docker container. I'm now looking to create the actual script that the CI job will run. I come from a Jenkins background, and there one would create a Jenkinsfile for this. We're probably not going to be using Jenkins for this project, so I'm looking for a tool that can be run regardless of the build server. The most straight forward way would probably be to script this build using bash or python or something. I'm quite new to both Drupal and PHP, so I'm wondering if there are any tools out there similar to Jenkinsfile I can make use of, which I can run on Gitlab or whatever other CI server we go for?
- snippet minor 112d agoHow can I calculate costs of deploying 1000 instances of Drupal?What are the things that should I investigate for making an estimate of the cost of deploying 1000 instances of Drupal, for example? I was thinking in: - Database space - Database usage (in ops/second? how can I test it?) - Application uploads space - Application processing time (again, how to measure?) - Bandwidth usage (for medium/low traffic sites) - DevOps / Technical Support time This is all about bringing a SaaS platform. Is there anything else I should take in consideration? How can I know how many "instances" would be able to run in a single host? Much like a Shared Hosting Would Amazon EC2 / Google / Azure be cheaper than having dedicated servers?
- principle minor 112d agoBest practice when automating Drupal (or other soft) installation regarding database settingsSuppose I have Drupal and CiviCRM installations to automate. These, however, need particular configs for working together (some file edits and database configs) Should I make a fixed version install (eg. Drupal 4.7.5 + CiviCRM 4.5.6), install them and configure, and then save the edited files plus database? Or should I put more effort in my build script and make some queries and seds to edit those configs in the database and files?
- snippet minor 112d agoHow can Jenkins help to implement CI/CD for Drupal?Assume you want to implement continuous-integration (= CI) and continuous-deployment (= CD) for building and maintaining websites using Drupal (let's assume for Drupal Version 7). Often times Jenkins seems to be recommended as one of the most appropriate solutions for doing so. But what kind of CI/CD related functionality can I actually use it for? Here are some of things I'm thinking of, but I'm not sure if I'm correct on that, and/or if these are the only things: - CI related: Automated testing. - CD related: Migrating custom module development between dev / staging / QA environments.
- snippet tip 120d agodrupal — Generate boilerplate code, interact with and debug Drupal projects. Some subcommands such as `check`How to use the `drupal` command: Generate boilerplate code, interact with and debug Drupal projects. Some subcommands such as `check` have their own usage documentation. `drupal` has been deprecated. Use `drush` instead. More information: <https://drupalize.me/topic/drupal-console>.