0

This is my first custom module to use Drupal for its data storage. So I've wired up the .info, .module and .install file as you'll see below. The .info, .module make it show up in Drupal but when I enable the module I see no table instantiated in mysql, and no warning, either.

What I did was copy the hook_schema from here and modified it as you'll see below.

/sites/default/modules/custom/issueTracker/issueTracker.module

function issueTracker_init() {
  // drupal_set_message(t('hell, jars'));
}

function issueTracker_menu() {
  $items = array();
  $items['issueTracker/custom'] = array(
    'title' => 'New issue',
    'description' => "Create new issue",
    'page callback' => 'drupal_get_form',
    'access arguments' => array('access content'),
    'page arguments' => array('issueTracker_form'),
    'access callback' => TRUE
    );
  return $items;
}

function issueTracker_permission() {
  return array(
    'custom path' => array(
      'title' => t('Access the custom path'),
      'description' => t('Allow users access to the custom path'),
    ),
  );
}

function issueTracker_help($path, $arg) {
  switch ($path) {
    case 'admin/help#issueTracker':
      return '<p>' . t('Form to capture user issues') . '</p>';
      break;
  }
}

function issueTracker_block_info(){
  $blocks['current issues'] = array(
    'info' => t('Current issues'),
    'cache' => DRUPAL_CACHE_PER_ROLE,
    );
  return $blocks;
}

function issueTracker_form($form, &$form_state) {
  $form['issueDescription'] = array(
    '#type' => 'textfield',
    '#title' => t('Issue Description'),
    '#size' => 255,
    '#maxlength' => 255,
    '#required' => TRUE,
    );
  $form['submit_button'] = array(
    '#type' => 'submit',
    '#value' => t('Click here'),
    );
  return $form;
}



function issueTracker_form_validate($form, &$form_state) {

}

function issueTracker_form_submit($form, &$form_state) {

}

function issueTracker_helper() {
  return '<p>Hell, jello</p>';
}

And my /sites/default/modules/custom/issueTracker/issueTracker.install

function issueTracker_schema() {
  $schema = array();
  $schema['domIssues'] = array(

    // Example (partial) specification for table "node".
    'description' => 'Tracking issues.',
    'fields' => array(
      'issueID' => array(
        'description' => 'The primary identifier for an issue.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'issueDate' => array(
        'description' => 'Date issue created.',
        'mysql_type' => 'DATETIME',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'issueDescription' => array(
        'description' => 'Issue details.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'lastModified' => array(
        'description' => 'Issue last touched.',
        'mysql_type' => 'DATETIME',
        'not null' => TRUE,
      ),
    ),
    // 'indexes' => array(
    //   'issue_changed' => array('changed'),
    //   'issue_created' => array('created'),
    // ),
    // 'unique keys' => array(
    //   'nid_vid' => array('nid', 'vid'),
    //   'vid' => array('vid'),
    // ),
    // 'foreign keys' => array(
    //   'node_revision' => array(
    //     'table' => 'node_revision',
    //     'columns' => array('vid' => 'vid'),
    //   ),
    //   'issue_author' => array(
    //     'table' => 'users',
    //     'columns' => array('uid' => 'uid'),
    //   // ),
    // ),
    'primary key' => array('issueID'),
  );
  return $schema;
}

And the output of my drush status:

 Drupal version                  :  7.32                                        
 Site URI                        :  http://default                              
 Database driver                 :  mysql                                       
 Database username               :  dbo                               
 Database name                   :  db                                 
 Database                        :  Connected                                   
 Drupal bootstrap                :  Successful                                  
 Drupal user                     :  Anonymous                                   
 Default theme                   :  velocity                                    
 Administration theme            :  seven                                       
 PHP executable                  :  /home/sam/.phpbrew/php/php-5.4.34/bin/php   
 PHP configuration               :  /home/sam/.phpbrew/php/php-5.4.34/etc/php.i 
                                    ni                                          
 PHP OS                          :  Linux                                       
 Drush version                   :  6.2.0                                       
 Drush configuration             :                                              
 Drush alias files               :                                              
 Drupal root                     :  /media/psf/Home/apps/umhef                  
 Site path                       :  sites/default                               
 File directory path             :  sites/default/files                         
 Temporary file directory path   :  sites/default/files/tmp 

I would expect that when I enable this module, either by drush or through the UI that there would be a table created called 'demises' based on my reading of the tutorials.

Knowing my history, it's likely some goof on my part and I asked myself, how do I know that I'm writing to the db as I expect. Looking on Stack I can see the module is listed in the system table and is enabled so it's likely I am writing to the same database, just get no info that I haven't written to the db.

What else can I use to troubleshoot this? thx, sam

  • Had the module been previously enabled before you added your hook_schema implementation? – ratface Mar 4 '15 at 20:44
  • Yes, and I flushed the cache earlier this a.m. – sam452 Mar 4 '15 at 20:45
  • 1
    The install file will only be executed the first time the module is enabled. Try disabling and un-installing (drush dis issueTracker && drush pm-uninstall issueTracker) and then enable again. – ratface Mar 4 '15 at 20:50
  • Also, Drupal convention is to used underscores in function names\db names rather than camel case. so issueTracker = issue_tracker and domIssues = dom_issues – ratface Mar 4 '15 at 20:52
  • Yes, that does work. I did not see that in the drupal guides like the above. I'd be grateful if you turned your comment into an answer! Thx. – sam452 Mar 4 '15 at 20:56
2

The install file will only be executed the first time the module is enabled. Try disabling and un-installing (drush dis issueTracker && drush pm-uninstall issueTracker) and then enable again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.