public function commit()
 {
     #echo __METHOD__ . "\n";
     #echo 'print_r($this): ' . "\n";
     #print_r($this) . "\n";
     if ($fh = fopen($this->get_name(), 'w')) {
         /*
          * Write the shebang.
          */
         fwrite($fh, $this->get_shebang());
         $cli_script_class_name = $this->get_cli_script_class_name();
         $eol = $this->get_eol();
         fwrite($fh, "<?php{$eol}");
         /*
          * Write a comment explaining the file.
          */
         $hpo_cm = Configuration_ConfigManagerHelper::get_config_manager('haddock', 'haddock-project-organisation');
         fwrite($fh, "/*{$eol}");
         fwrite($fh, " * Script object runner for {$cli_script_class_name} {$eol}");
         fwrite($fh, " *{$eol}");
         fwrite($fh, ' * @copyright ' . date('Y-m-d') . ', ' . $hpo_cm->get_copyright_holder() . $eol);
         fwrite($fh, " */{$eol}");
         fwrite($fh, $eol);
         /*
          * Check that the SAPI is 'cli'.
          *
          * We don't want this scripts to be run on
          * a web server!
          */
         fwrite($fh, "if (PHP_SAPI == 'cli') { {$eol}");
         /*
          * Define the project root.
          */
         fwrite($fh, "define('PROJECT_ROOT', '" . PROJECT_ROOT . "');{$eol}");
         /*
          * Define the debug constants.
          */
         fwrite($fh, "require_once PROJECT_ROOT . '/haddock/code-analysis/includes/define-debug-constants.inc.php';{$eol}");
         /*
          * Define the __autoload function.
          */
         fwrite($fh, "require PROJECT_ROOT . '/haddock/haddock-project-organisation/includes/autoload.inc.php';{$eol}");
         /*
          * Parse the args.
          */
         fwrite($fh, "\$args = CLIScripts_ArgsHelper::parse_argv(\$_SERVER['argv']);{$eol}");
         /*
          * Run the class.
          */
         fwrite($fh, "\ntry {\n\t\$script_class_reflection_class = new ReflectionClass('{$cli_script_class_name}');\n\t\n\t\$script_class_reflection_object\n\t\t= \$script_class_reflection_class\n\t\t\t->newInstanceArgs(\n\t\t\t\tarray(\n\t\t\t\t\t\$args\n\t\t\t\t)\n\t\t\t);\n\t\n\t\$script_class_reflection_object->main();\n} catch (Exception \$e) {\n\tCLIScripts_ExceptionsHelper\n\t\t::render_exception_trace(\$e);\n}\n");
         fwrite($fh, "}{$eol}");
         fwrite($fh, "?>{$eol}");
         fclose($fh);
         chmod($this->get_name(), 0755);
     }
 }
 public function __construct(CLIScripts_LockFile $lock_file)
 {
     parent::__construct();
     $tism_cm = Configuration_ConfigManagerHelper::get_config_manager('plug-ins', 'trackit-stock-management');
     #$email_to = '*****@*****.**';
     #$email_to = '*****@*****.**';
     $email_to = $tism_cm->get_dlfre_to();
     $this->set_to($email_to);
     #$subject_template = "Lock file removed";
     $subject_template = $tism_cm->get_dlfre_subject_template();
     $this->set_subject_template($subject_template);
     $this->add_template_variable('process_id', $lock_file->get_process_id());
     $this->add_template_variable('lock_file_ctime', date('c', $lock_file->ctime()));
     $this->add_template_variable('current_time', date('c'));
     $this->add_template_variable('lock_file_name', $lock_file->get_name());
     $this->add_template_variable('hostname', Environment_MachineHelper::get_real_host_name());
     #		$body_template =
     #'A dead lock file called:
     #
     #${lock_file_name}
     #
     #on
     #
     #${hostname}
     #
     #which had been created at:
     #
     #${lock_file_ctime}
     #
     #was removed at
     #
     #${current_time}
     #
     #The lock file had been for the process with PID:
     #
     #${process_id}
     #
     #';
     $body_template = $tism_cm->get_dlfre_body_template();
     $this->set_body_template($body_template);
     #$from_address = '*****@*****.**';
     #$from_address = get_current_user() . '@' . $_ENV['HOSTNAME'];
     #
     #$this->set_from($from_address);
     #echo 'print_r($this):' . "\n";
     #print_r($this);
 }
 public static function process_photographs()
 {
     #echo __METHOD__ . "\n";
     $tsm_cm = Configuration_ConfigManagerHelper::get_config_manager('plug-ins', 'trackit-stock-management');
     /*
      * Create the database objects.
      */
     $muf = Database_MySQLUserFactory::get_instance();
     $mu = $muf->get_for_this_project();
     $database = $mu->get_database();
     $feed_files_table = $database->get_table('hpi_trackit_stock_management_feed_files');
     /*
      * Get the list of photographs to process.
      */
     $ps = $feed_files_table->get_photographs_to_process();
     $cache_dir_name = $tsm_cm->get_cache_dir_name();
     $resized_photos_temporary_dir_name = $tsm_cm->get_resized_photos_temporary_dir_name();
     if (!is_dir($resized_photos_temporary_dir_name)) {
         system("mkdir -p {$resized_photos_temporary_dir_name}");
     }
     /*
      * Resize them.
      */
     foreach ($ps as $p) {
         $cache_file_name = "{$cache_dir_name}/" . $p->get('name');
         #echo "\$cache_file_name: $cache_file_name\n";
         $sizes = $tsm_cm->get_photograph_sizes();
         for ($i = 0; $i < count($sizes); $i++) {
             /*
              * Resize the image in the temporary dir.
              */
             $sizes[$i]['tmp_file_name'] = "{$resized_photos_temporary_dir_name}/" . $sizes[$i]['name'] . '_' . $p->get('name');
             $cmd = 'cp "' . $cache_file_name . '" "' . $sizes[$i]['tmp_file_name'] . '"';
             #echo "\$cmd: $cmd\n";
             system($cmd);
             $cmd = 'mogrify ' . ' -resize ' . $sizes[$i]['x'] . 'x' . $sizes[$i]['y'] . ' ' . '"' . $sizes[$i]['tmp_file_name'] . '"';
             #echo "\$cmd: $cmd\n";
             system($cmd);
         }
         $feed_files_table->record_process($p->get('name'));
     }
 }
 protected function get_limits_str()
 {
     #return '10 20 50 100 250 500 1000';
     $db_cm = Configuration_ConfigManagerHelper::get_config_manager('haddock', 'database');
     return $db_cm->get_crud_admin_page_limits_string();
 }
示例#5
0
/**
 * The main .INC for the process-stock-files script.
 *
 * @copyright 2007-11-26, RFI
 */
$debug = FALSE;
#$debug = TRUE;
if ($debug) {
    CodeAnalysis_MemoryHelper::cli_print_memory_usage('Start');
    $start_time = microtime(TRUE);
}
/*
 * Create the config manager objects.
 */
$tsm_cm = Configuration_ConfigManagerHelper::get_config_manager('plug-ins', 'trackit-stock-management');
if ($debug) {
    CodeAnalysis_MemoryHelper::cli_print_memory_usage('Created config manager');
}
/*
 * Find out if there is an instance of this file already running.
 */
$process_stock_text_files_lock_file = TrackitStockManagement_FeedFilesHelper::get_process_stock_text_files_lock_file();
if ($process_stock_text_files_lock_file->is_locked()) {
    throw new Exception('The process-stock-files script is locked!');
} else {
    $process_stock_text_files_lock_file->lock();
    /*
     * Create the database objects.
     */
    $muf = Database_MySQLUserFactory::get_instance();
 public function __construct($locked_script_name)
 {
     $cs_cm = Configuration_ConfigManagerHelper::get_config_manager('haddock', 'cli-scripts');
     parent::__construct($cs_cm->get_script_locked_exception_format_string(), $locked_script_name);
 }
 public static function get_cache_dir_name()
 {
     $tsm_cm = Configuration_ConfigManagerHelper::get_config_manager('plug-ins', 'trackit-stock-management');
     $cache_dir_name = $tsm_cm->get_cache_dir_name();
     return $cache_dir_name;
 }
 private function get_config_manager()
 {
     return Configuration_ConfigManagerHelper::get_config_manager('plug-ins', 'protx-payments');
 }
 public static function get_process_image_text_files_lock_file_name()
 {
     $cm = Configuration_ConfigManagerHelper::get_config_manager('plug-ins', 'trackit-stock-management');
     return $cm->get_pitf_lock_file_name();
 }
 public static function unlock_all_lock_files()
 {
     $tsm_cm = Configuration_ConfigManagerHelper::get_config_manager('plug-ins', 'trackit-stock-management');
     $lock_files_directory = $tsm_cm->get_lock_files_directory();
     $lock_files_directory->unlock_all_lock_files();
 }