/[drupal]/contributions/modules/api/api.module
ViewVC logotype

Diff of /contributions/modules/api/api.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.58 by drumm, Fri Aug 15 07:59:50 2008 UTC revision 1.59 by drumm, Fri Aug 15 08:01:10 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: api.module,v 1.57 2008/08/15 07:59:06 drumm Exp $  // $Id: api.module,v 1.58 2008/08/15 07:59:50 drumm Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 86  function api_get_branches() { Line 86  function api_get_branches() {
86    static $branches;    static $branches;
87    
88    if (!isset($branches)) {    if (!isset($branches)) {
89      $result = db_query('SELECT branch_name, title FROM {api_branch}');      $result = db_query('SELECT branch_name, title, directory FROM {api_branch}');
90      $branches = array();      $branches = array();
91      while ($branch = db_fetch_object($result)) {      while ($branch = db_fetch_object($result)) {
92        $branches[$branch->branch_name] = $branch;        $branches[$branch->branch_name] = $branch;
# Line 1072  function api_page_admin_form() { Line 1072  function api_page_admin_form() {
1072      );      );
1073    }    }
1074    
   $options = array(  
     10 => '10',  
     20 => '20',  
     30 => '30',  
     50 => '50',  
     100 => '100',  
     200 => '200',  
   );  
   $form['api_files_per_cron'] = array(  
     '#type' => 'select',  
     '#title' => t('Maximun files to scan per cron run'),  
     '#default_value' => variable_get('api_files_per_cron', 10),  
     '#options' => $options,  
     '#description' => t('Default is 10. It is not recommended to increase this, except temporarily if a large amount of files are to be indexed (ie, a new branch has been added).'),  
   );  
   
1075    $form['submit'] = array(    $form['submit'] = array(
1076      '#type' => 'submit',      '#type' => 'submit',
1077      '#value' => t('Save changes'),      '#value' => t('Save changes'),
# Line 1132  function api_page_admin_form_submit($for Line 1116  function api_page_admin_form_submit($for
1116      variable_set('api_default_branch', $form_state['values']['default_branch']);      variable_set('api_default_branch', $form_state['values']['default_branch']);
1117    }    }
1118    
   // Save the variable for max files per cron.  
   variable_set('api_files_per_cron', $form_state['values']['api_files_per_cron']);  
   
1119    // We may have menu changes, so clear the menu cache for all users.    // We may have menu changes, so clear the menu cache for all users.
1120    cache_clear_all('*', 'cache_menu', TRUE);    cache_clear_all('*', 'cache_menu', TRUE);
1121    
# Line 1189  function api_reindex_form_submit($form, Line 1170  function api_reindex_form_submit($form,
1170   * Implementation of hook_cron().   * Implementation of hook_cron().
1171   */   */
1172  function api_cron() {  function api_cron() {
1173    require_once(drupal_get_path('module', 'api') .'/parser.inc');    include_once './'. drupal_get_path('module', 'api') .'/parser.inc';
1174      api_update_all_branches();
   $files_scanned = 0;  
   $max_files = variable_get('api_files_per_cron', 10);  
   
   db_query("UPDATE {api_file} SET found = 0");  
   
   $branches = db_query('SELECT branch_name, directory FROM {api_branch}');  
   while ($branch = db_fetch_object($branches)) {  
     $files = api_scan_directories($branch->directory);  
     foreach ($files as $path => $file_name) {  
       if ($files_scanned >= $max_files) {  
         break;  
       }  
   
       $modified = 0;  
       $result = db_query("SELECT f.did, f.modified FROM {api_documentation} d INNER JOIN {api_file} f ON d.did = f.did WHERE d.object_name = '%s' AND d.branch_name = '%s' AND d.object_type = 'file'", $file_name, $branch->branch_name);  
       if ($file = db_fetch_object($result)) {  
         $modified = $file->modified;  
         db_query("UPDATE {api_file} SET found = 1 WHERE did = %d", $file->did);  
       }  
   
       if (filemtime($path) > $modified) {  
         if (api_parse_file($path, $branch->branch_name, $file_name)) {  
           $files_scanned++;  
         }  
       }  
     }  
   }  
   
   // Remove outdated files.  
   if ($files_scanned == 0) {  
     $result = db_query("SELECT ad.file_name, ad.branch_name FROM {api_file} af LEFT JOIN {api_documentation} ad ON ad.did = af.did WHERE af.found = 0");  
     while ($file = db_fetch_object($result)) {  
       watchdog('api', 'Removing %file', array('%file' => $file->file_name));  
       $doc_result = db_query("SELECT ad.did FROM {api_documentation} ad WHERE ad.file_name = '%s' AND ad.branch_name = '%s'", $file->file_name, $file->branch_name);  
       while ($doc = db_fetch_object($doc_result)) {  
         db_query("DELETE FROM {api_documentation} WHERE did = %d", $doc->did);  
         db_query("DELETE FROM {api_file} WHERE did = %d", $doc->did);  
         db_query("DELETE FROM {api_function} WHERE did = %d", $doc->did);  
         db_query("DELETE FROM {api_reference_storage} WHERE from_did = %d OR to_did = %d", $doc->did, $doc->did);  
       }  
     }  
   }  
   
   // Update any references that were resolved during this run.  
   api_update_references();  
   
   if ($files_scanned != 0) {  
     // Some files were updated, so clear the page cache  
     cache_clear_all();  
   }  
1175  }  }
1176    
1177  /**  /**
# Line 1401  function api_link_name($name, $branch_na Line 1332  function api_link_name($name, $branch_na
1332      return $prepend . $name . $append;      return $prepend . $name . $append;
1333    }    }
1334  }  }
   
 /**  
  * Find all the files in the directories specified for a branch.  
  */  
 function api_scan_directories($directories) {  
   $directory_array = explode(':', $directories);  
   
   if (count($directory_array) > 1) {  
     $directories_components = array();  
     foreach ($directory_array as $directory) {  
       $directory_components = array();  
       $parts = explode('/', $directory);  
       foreach ($parts as $part) {  
         if (strlen($part)) {  
           array_unshift($directory_components, reset($directory_components) .'/'. $part);  
         }  
       }  
       $directories_components[] = $directory_components;  
     }  
   
     $common_ancestor_components = call_user_func_array('array_intersect', $directories_components);  
     $common_ancestor = reset($common_ancestor_components);  
   }  
   else {  
     $common_ancestor = $directories;  
   }  
   
   $source_files = array();  
   foreach ($directory_array as $directory) {  
     $files = file_scan_directory($directory, '.*');  
     foreach ($files as $path => $file) {  
       if (strpos($path, '/.') !== FALSE) {  
         continue;  
       }  
       $file_name = substr($path, strlen($common_ancestor) + 1);  
   
       $source_files[$path] = $file_name;  
     }  
   }  
   return $source_files;  
 }  
   
 function api_simpletest() {  
   $dir = drupal_get_path('module', 'api') .'/tests';  
   return array_keys(file_scan_directory($dir, '\.test$'));  
 }  

Legend:
Removed from v.1.58  
changed lines
  Added in v.1.59

  ViewVC Help
Powered by ViewVC 1.1.3