Преглед на файлове

Let ODT template be a parameter of the drush command

Yves Chedemois преди 15 години
родител
ревизия
bbc4f73b46
променени са 5 файла, в които са добавени 25 реда и са изтрити 26 реда
  1. 13 25
      fgcf.drush.inc
  2. 1 0
      fgcf.import.inc
  3. 3 0
      fgcf.install
  4. 2 1
      fgcf.module
  5. 6 0
      fgcf.odt.inc

+ 13 - 25
fgcf.drush.inc

@@ -4,9 +4,6 @@
  * @file
  * Fonctions de ligne de commande pour FGCF
  *
- * - importation de prestataires
- * - importation de fiches de formation
- *
  * Copyright 2010 Ouest Systemes Informatiques (OSInet)
  *
  * Licensed under the General Public License, version 2 or later
@@ -20,29 +17,19 @@
  */
 function fgcf_drush_command() {
   $items['fgcf-catalog'] = array(
-    // a short description of your command
     'description' => "Génère un catalogue de formations au format OpenDocument.",
+    'arguments' => array(
+      'template' => "Le fichier de template à utiliser (format ODT). Le fichier doit se trouver dans le répertoire d'installation de Drupal",
+    ),
     'options' => array(
       'dest' => "Le nom du fichier à générer. Le chemin est relatif au répertoire d'installation Drupal.\nPar défaut un fichier catalogue.odt est généré dans le répertoire d'installation Drupal.",
     ),
     'examples' => array(
-      'drush fgcf-catalog' => 'Génère un fichier catalogue.otf dans le répertoire Drupal, à partir du template template.odt présent dans le répertoire courant',
-      'drush fgcf-catalog --dest=../custom.otf' => 'Génère un fichier custom.otf dans le dossier parent du répertoire Drupal, à partir du template template.odt présent dans le répertoire courant',
+      'drush fgcf-catalog template.odt' => "Génère un fichier catalogue.otf dans le répertoire Drupal, à partir du template template.odt présent dans le répertoire d'installation Drupal",
+      'drush fgcf-catalog template.odt --dest=../custom.otf' => "Génère un fichier custom.otf dans le dossier parent du répertoire Drupal, à partir du template template.odt présent dans le répertoire d'installation Drupal",
     ),
     'aliases' => array('fgcfc'),
   );
-
-//  $items['fgcf-import-prestataires'] = array(
-//    // a short description of your command
-//    'description' => "Importe des fiches de prestataires depuis un fichier",
-//    'aliases' => array('fgcf-p'),
-//  );
-//
-//  $items['fgcf-import-formations'] = array(
-//    // a short description of your command
-//    'description' => "Importe des fiches de formation depuis un fichier",
-//    'aliases' => array('fgcf-f'),
-//  );
   return $items;
 }
 
@@ -53,12 +40,9 @@ function fgcf_drush_command() {
  */
 function fgcf_drush_help($section) {
   $help = array(
-    'fgcf-catalog'   => dt('Génère un catalogue de formations à partir du fichier catalogue_template.odt présent dans le dossier du module fgcf.'),
-//    'fgcf-import-prestataires' => dt('Importe toutes les fiches de prestataires trouvées dans le fichier passé en argument'),
-//    'fgcf-import-formations'   => dt('Importe toutes les fiches de formations trouvées dans le fichier passé en argument'),
+    'drush:fgcf-catalog'   => dt('Génère un catalogue de formations à partir du fichier catalogue_template.odt présent dans le dossier du module fgcf.'),
   );
 
-  $key = substr($section, strlen('drush:')); // drupal_substr() not available
   return array_key_exists($key, $help) ? $help[$key] : NULL;
 }
 
@@ -67,14 +51,18 @@ function fgcf_drush_help($section) {
  *
  * @param string $filename
  */
-function drush_fgcf_catalog() {
-  // @todo : à paramétrer ?
-  $template = dirname(__FILE__) ."/catalogue_template.odt";
+function drush_fgcf_catalog($template = NULL) {
   $dest = drush_get_option('dest');
   if (empty($dest)) {
     $dest = 'catalogue.odt';
   }
 
+  if (empty($template)) {
+    return drush_set_error("Vous devez préciser le fichier de modèle à utiliser.");
+  }
+  if (!file_exists($template)) {
+    return drush_set_error("Le fichier $template n'a pas été trouvé dans le dossier d'installation drupal.");
+  }
   module_load_include('inc', 'fgcf', 'fgcf.odt');
   $odf = fgcf_odt_export_formations($template);
   $odf->saveToDisk($dest);

+ 1 - 0
fgcf.import.inc

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * @file
  * Export / import functions.

+ 3 - 0
fgcf.install

@@ -1,5 +1,8 @@
 <?php
 
+/**
+ * Implementation of hook_install().
+ */
 function fgcf_install() {
   $vocabulary = array(
     'name' => 'FGCF Thématique',

+ 2 - 1
fgcf.module

@@ -43,7 +43,7 @@ function fgcf_menu() {
 //  $items['fgcf/odt'] = array(
 //    'title' => 'ODT Test',
 //    'page callback' => 'fgcf_page_odt',
-//    'access callback' => $read_access,
+//    'access arguments' => $read_access,
 //  );
   return $items;
 }
@@ -304,6 +304,7 @@ function fgcf_page_odt() {
   module_load_include('inc', 'fgcf', 'fgcf.odt');
 
   $template = dirname(__FILE__) ."/catalogue_template.odt";
+  $template = "catalogue_template.odt";
   $odf = fgcf_odt_export_formations($template);
   $odf->exportAsAttachedFile('catalogue.odt');
 }

+ 6 - 0
fgcf.odt.inc

@@ -1,5 +1,11 @@
 <?php
 
+/**
+ * @file
+ *
+ * Generation of catalog of 'fiche formation' nodes in ODT format.
+ */
+
 /**
  * Load the OdtPHP library and initialize some variables.
  */