I've just started out with Drupal. I'm still alpha testing my site, found out the hard way regarding using the correct module versions, and already dreading future upgrades.

My suggestion is for a way to know the version numbers, particularly of modules and your Drupal installation, without going looking through the files themselves, which in most cases mean ftp. Of course, if you maintain the site, the onus is to keep a note of them. What I do is to keep the downloads of the gzip files so I can tell which versions I have.

But what happens if you lose them, or take over somebody else's installation. Ftp downloading and reading text files are a chore.

Let me apologize first as I haven't done any major php coding (only changed a line here or there, or code-copied), or if this is being worked on, but I hopefully can point someone in the right direction.

In well-coded files, the second line usually contain the Id's so I think this is the only location for the version numbers. The system database also holds the info on the modules. I can think of 3 ways on how to get the numbers from the browser interface:

1. A script to read the second line from each module, either one-by-one (quick) if you make the link from the module settings page, or the whole gamut (lots of file lookups). Reading the text files however doesn't sound like good security, and would take lots of php filters to get to the number.

2. A change to the system database to add the Id column. Then it would be easy to make a script to lookup the database. I guess the place to start is in module.inc when it loads the module, but this would be a version step. And still you need to read the text file.

3. Introduce a new variable for version to be included in every module so that it can be loaded into and from the database (hmm, Drupal 5.0?).

As for Drupal version number, shouldn't it have been easily found (its own database or variable perhaps).

You can also extend this to inc or tpl files but that would be too much.

Having another variable like url would be useful too so that you can easily jump to the relevant page in drupal. I keep going to drupal>>downloads>>modules, scroll down, click 'find out more', go to the module's page to check any info, issues, new versions, etc. Wouldn't it be easy if you could jump to it straight from administer>>modules :)

Comments

zhzrj’s picture

I've come up with a simple script based on just a few weeks of php familiarisation, that can list versions by reading the module files:

<?php 
  $m_result=db_query("SELECT name, filename, status FROM {system} WHERE type = 'module'");
  while ($m_list = db_fetch_object($m_result)) {
    //Here you could format the array values into a nice string, but just to have a look, you can print the whole thing at once
    print_r($m_list);
    print "<br>";
    if ($m_lines = file($m_list->filename)){
      //You can use
      //print htmlspecialchars($m_lines[1]);
      //but some modules don't have their Id's on the 2nd line,
      //so this section just searches the 1st 5 lines for it
      $i=0;
      while ( ($id_found=!strripos($m_lines[$i],'$Id')) && $i<=5 ) {
        $i++;
      }
      if (!$id_found){
        print htmlspecialchars($m_lines[$i]);
        print " at line".$i; //If you want to know which line it's on
      } else {
        print "Id not found in first 5 lines of file.";
      }
    } else {
      print $m_list->filename." does not exist.";
    }
    print "<br><br>";
  }
?>

In a similar fashion, you could also get the Drupal version:

<?php
  $c_lines=file('CHANGELOG.txt');
  print htmlspecialchars($c_lines[0])."<br>";
?>

Some thoughts on this:

  1. Had to do a db query. Drupal has a list function for modules, module_list(), but unfortunately it does not list the full path of the filename.
  2. I hope the code managed to catch most of the errors (like lost files or unstated Ids). The file paths I expect should not cause any problems but then my Drupal is in the root directory. There could also be odd Id clarifications, like on multiple lines on not using $Id, but have not encountered any other than not being on the 2nd line or totally non-existent.
  3. I believe the code could be tighter. Furthermore, I'm sure there are better ways to read the files, to make it faster and less memory intensive.
  4. The values of course can be put into another array which you can then sort and put in a nice table or divs. Could someone try to split the Id line so that you can extract the version without using too many expressions?
  5. SECURITY: I don't know whether it's OK to peek into the module files (or changelog.txt) and whether it would work if you set different file permissions.

Now my question is, where should I put this code? I tested in on an unused node template (thank god for XAMPP). I can create it as a page but it would be nicer if it was a template or module itself rather than a node content, but I'm not sure how to do that.

zhzrj’s picture

Silly me, I'd expected that the Id's would have shown the version but unfortunately it didn't. Still, it's a starting point.

Could have made it to read the other text files, like readme, license, or install, but it's not uniform and personally, I don't save them on the web to conserve space.

Changelog read was OK.