[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ -> ezpm.php (source)

   1  #!/usr/bin/env php
   2  <?php
   3  //
   4  // Created on: <18-Mar-2003 17:06:45 amos>
   5  //
   6  // SOFTWARE NAME: eZ publish
   7  // SOFTWARE RELEASE: 3.9.0
   8  // BUILD VERSION: 17785
   9  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  10  // SOFTWARE LICENSE: GNU General Public License v2.0
  11  // NOTICE: >
  12  //   This program is free software; you can redistribute it and/or
  13  //   modify it under the terms of version 2.0  of the GNU General
  14  //   Public License as published by the Free Software Foundation.
  15  //
  16  //   This program is distributed in the hope that it will be useful,
  17  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  //   GNU General Public License for more details.
  20  //
  21  //   You should have received a copy of version 2.0 of the GNU General
  22  //   Public License along with this program; if not, write to the Free
  23  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24  //   MA 02110-1301, USA.
  25  //
  26  
  27  //
  28  
  29  include_once ( "lib/ezutils/classes/ezextension.php" );
  30  include_once ( "lib/ezutils/classes/ezmodule.php" );
  31  include_once ( 'lib/ezutils/classes/ezcli.php' );
  32  include_once ( 'kernel/classes/ezscript.php' );
  33  
  34  $cli =& eZCLI::instance();
  35  $script =& eZScript::instance( array( 'debug-message' => '',
  36                                        'use-session' => true,
  37                                        'use-modules' => true,
  38                                        'use-extensions' => true ) );
  39  
  40  $script->startup();
  41  include_once ( 'kernel/common/i18n.php' );
  42  
  43  $endl = $cli->endlineString();
  44  $webOutput = $cli->isWebOutput();
  45  
  46  function help()
  47  {
  48      $argv = $_SERVER['argv'];
  49      $cli =& eZCLI::instance();
  50      $cli->output( "Usage: " . $argv[0] . " [OPTION]... COMMAND [COMMAND OPTION]... [-- COMMAND [COMMAND OPTION]...]...\n" .
  51                    "eZ publish package manager.\n" .
  52                    "\n" .
  53                    "Type " . $argv[0] . " help for command overview\n" .
  54                    "\n" .
  55                    "General options:\n" .
  56                    "  -h,--help            display this help and exit \n" .
  57                    "  -q,--quiet           do not give any output except when errors occur\n" .
  58                    "  -s,--siteaccess      selected siteaccess for operations, if not specified default siteaccess is used\n" .
  59                    "  -d,--debug           display debug output at end of execution\n" .
  60                    "  -c,--colors          display output using ANSI colors (default)\n" .
  61                    "  -l,--login USER      login with USER and use it for all operations\n" .
  62                    "  -p,--password PWD    use PWD as password for USER\n" .
  63                    "  -r,--repos REPOS     use REPOS for repository when accessing packages\n" .
  64                    "  --db-type TYPE       set type of db to use\n" .
  65                    "  --db-name NAME       set name of db to use\n" .
  66                    "  --db-user USER       set database user\n" .
  67                    "  --db-password PASSWD set password for database user\n" .
  68                    "  --db-socket SOCKET   set socket for db connection\n" .
  69                    "  --db-host HOST       set host name for db connection\n" .
  70                    "  --logfiles           create log files\n" .
  71                    "  --no-logfiles        do not create log files (default)\n" .
  72                    "  --no-colors          do not use ANSI coloring\n" );
  73  }
  74  
  75  function helpCreate()
  76  {
  77      $cli =& eZCLI::instance();
  78      $cli->output( "create: Create a new package.\n" .
  79                    "usage: create NAME [SUMMARY [VERSION [INSTALLTYPE]]] [PARAMETERS]\n" .
  80                    "\n" .
  81                    "SUMMARY:     A short summary of your package\n" .
  82                    "VERSION:     The version of your package, default is 1.0\n" .
  83                    "INSTALLTYPE: Use install (default) for a package that installs files or\n" .
  84                    "             import for a package that can only be imported.\n" .
  85                    "Parameters:\n"
  86                    );
  87  }
  88  
  89  function helpExport()
  90  {
  91      $cli =& eZCLI::instance();
  92      $cli->output( "export: Export a part of the eZ publish installation into a package.\n" .
  93                    "usage: export TYPE [PARAMETERS]... [TYPE [PARAMETERS]...]...\n" .
  94                    "\n" .
  95                    "Options:\n" .
  96                    "  -o,--output FILE   export to file\n"
  97                    );
  98  }
  99  
 100  function helpInstall()
 101  {
 102      $cli =& eZCLI::instance();
 103      $cli->output( "import: Install an eZ publish package.\n" .
 104                    "usage: install PACKAGE\n" .
 105                    "\n" .
 106                    "PACKAGE can be specified with just the name of the of package or\n" .
 107                    "the filename of the package. If just the name is used the package\n" .
 108                    "will be looked for by appending .ezpkg\n"
 109                    );
 110  }
 111  
 112  function helpImport()
 113  {
 114      $cli =& eZCLI::instance();
 115      $cli->output( "import: Import an eZ publish package.\n" .
 116                    "usage: import PACKAGE\n" .
 117                    "\n" .
 118                    "PACKAGE can be specified with just the name of the of package or\n" .
 119                    "the filename of the package. If just the name is used the package\n" .
 120                    "will be looked for by appending .ezpkg\n"
 121                    );
 122  }
 123  
 124  function helpList()
 125  {
 126      $cli =& eZCLI::instance();
 127      $cli->output( "list (ls): Lists all packages in the repository.\n" .
 128                    "usage: list\n"
 129                    );
 130  }
 131  
 132  function helpInfo()
 133  {
 134      $cli =& eZCLI::instance();
 135      $cli->output( "info: Displays information on a given package.\n" .
 136                    "usage: info PACKAGE\n"
 137                    );
 138  }
 139  
 140  function helpAdd()
 141  {
 142      $cli =& eZCLI::instance();
 143      $cli->output( "add: Adds an eZ publish item to the package.\n" .
 144                    "usage: add PACKAGE ITEM [ITEMPARAMETERS]...\n" .
 145                    "\n" .
 146                    "Items:\n" .
 147                    "  group: Add categorization groups\n" .
 148                    "  ezcontentclass: Add contentclass definitions\n" .
 149                    "Note: Will open up a new release if no open releases exists yet.\n"
 150                    );
 151  }
 152  
 153  function helpSet()
 154  {
 155      $cli =& eZCLI::instance();
 156      $cli->output( "set: Sets an attribute in the package.\n" .
 157                    "usage: set PACKAGE ATTRIBUTE ATTRIBUTEVALUE\n" .
 158                    "\n" .
 159                    "Attributes:\n" .
 160                    "  summary     :\n" .
 161                    "  description :\n" .
 162                    "  vendor      :\n" .
 163                    "  priority    :\n" .
 164                    "  type        :\n" .
 165                    "  extension   :\n" .
 166                    "  source      :\n" .
 167                    "  version     :\n" .
 168                    "  licence     :\n" .
 169                    "  state       :\n" .
 170                    "Note: Will open up a new release if no open releases exists yet.\n"
 171                    );
 172  }
 173  
 174  function helpDelete()
 175  {
 176      $cli =& eZCLI::instance();
 177      $cli->output( "delete (del, remove, rm): Removes an eZ publish item from the package.\n" .
 178                    "usage: delete PACKAGE ITEM [ITEMPARAMETERS]...\n" .
 179                    "\n" .
 180                    "Note: Will open up a new release if no open releases exists yet.\n"
 181                    );
 182  }
 183  
 184  function helpHelp()
 185  {
 186      $argv = $_SERVER['argv'];
 187      $cli =& eZCLI::instance();
 188      $cli->output( "help: Displays help information on commands.\n" .
 189                    "usage: help COMMAND\n" .
 190                    "\n" .
 191                    "Type \"" . $argv[0] . " help COMMAND\" for help on a specific command.\n" .
 192                    "\n" .
 193                    "Available commands:\n" .
 194                    "   help (?, h)\n" .
 195                    "   create\n" .
 196                    "   install\n" .
 197                    "   import\n" .
 198                    "   export\n" .
 199                    "   add\n" .
 200                    "   set\n" .
 201  //                  "   delete (del, remove, rm)\n" .
 202                    "   list\n" .
 203                    "   info\n"
 204                    );
 205  }
 206  
 207  function changeSiteAccessSetting( &$siteaccess, $optionData )
 208  {
 209      global $isQuiet;
 210      $cli =& eZCLI::instance();
 211      if ( file_exists( 'settings/siteaccess/' . $optionData ) )
 212      {
 213          $siteaccess = $optionData;
 214          if ( !$isQuiet )
 215              $cli->notice( "Using siteaccess $siteaccess for package creating" );
 216      }
 217      else
 218      {
 219          if ( !$isQuiet )
 220              $cli->notice( "Siteaccess $optionData does not exist, using default siteaccess" );
 221      }
 222  }
 223  
 224  $siteaccess = false;
 225  $debugOutput = false;
 226  $allowedDebugLevels = false;
 227  $useDebugAccumulators = false;
 228  $useDebugTimingpoints = false;
 229  $useIncludeFiles = false;
 230  $useColors = true;
 231  $isQuiet = false;
 232  $useLogFiles = false;
 233  $userLogin = false;
 234  $userPassword = false;
 235  $command = false;
 236  $repositoryPath = false;
 237  
 238  $dbUser = false;
 239  $dbPassword = false;
 240  $dbSocket = false;
 241  $dbHost = false;
 242  $dbType = false;
 243  $dbName = false;
 244  
 245  // $packageName = false;
 246  // $packageAttribute = false;
 247  // $packageAttributeValue = false;
 248  // $packagePart = false;
 249  // $packagePartParameters = array();
 250  // $packageSummary = false;
 251  // $packageLicence = false;
 252  // $packageVersion = false;
 253  // $packageFile = false;
 254  
 255  $commandList = array();
 256  $commandItem = array();
 257  
 258  function resetCommandItem( &$commandItem )
 259  {
 260      $commandItem = array( 'command' => false,
 261                            'name' => false,
 262                            'attribute' => false,
 263                            'attribute-value' => false,
 264                            'item' => false,
 265                            'item-parameters' => array(),
 266                            'summary' => false,
 267                            'installtype' => false,
 268                            'version' => false,
 269                            'file' => false );
 270  }
 271  
 272  function appendCommandItem( &$commandList, &$commandItem )
 273  {
 274      $commandList[] = $commandItem;
 275  }
 276  
 277  resetCommandItem( $commandItem );
 278  
 279  $optionsWithData = array( 's', 'o', 'l', 'p', 'r' );
 280  $longOptionsWithData = array( 'siteaccess', 'login', 'password', 'repos',
 281                                'db-type', 'db-name', 'db-user', 'db-password', 'db-socket', 'db-host' );
 282  
 283  $commandAlias = array();
 284  $commandAlias['help'] = array( '?', 'h' );
 285  $commandAlias['delete'] = array( 'del', 'remove', 'rm' );
 286  $commandAlias['list'] = array( 'ls' );
 287  $commandMap = array();
 288  
 289  foreach ( $commandAlias as $alias => $list )
 290  {
 291      foreach ( $list as $commandName )
 292      {
 293          $commandMap[$commandName] = $alias;
 294      }
 295  }
 296  
 297  $readOptions = true;
 298  
 299  for ( $i = 1; $i < count( $argv ); ++$i )
 300  {
 301      $arg = $argv[$i];
 302      if ( $arg == '--' )
 303      {
 304          appendCommandItem( $commandList, $commandItem );
 305          resetCommandItem( $commandItem );
 306      }
 307      else if ( $readOptions and
 308           strlen( $arg ) > 0 and
 309           $arg[0] == '-' )
 310      {
 311          if ( strlen( $arg ) > 1 and
 312               $arg[1] == '-' )
 313          {
 314              $flag = substr( $arg, 2 );
 315              if ( preg_match( '#^([^=]+)=(.+)$#', $flag, $matches ) )
 316              {
 317                  $flag = $matches[1];
 318                  $optionData = $matches[2];
 319              }
 320              else if ( in_array( $flag, $longOptionsWithData ) )
 321              {
 322                  $optionData = $argv[$i+1];
 323                  ++$i;
 324              }
 325              if ( $flag == 'help' )
 326              {
 327                  help();
 328                  exit();
 329              }
 330              else if ( $flag == 'siteaccess' )
 331              {
 332                  changeSiteAccessSetting( $siteaccess, $optionData );
 333              }
 334              else if ( $flag == 'debug' )
 335              {
 336                  $debugOutput = true;
 337              }
 338              else if ( $flag == 'quiet' )
 339              {
 340                  $isQuiet = true;
 341              }
 342              else if ( $flag == 'colors' )
 343              {
 344                  $useColors = true;
 345              }
 346              else if ( $flag == 'no-colors' )
 347              {
 348                  $useColors = false;
 349              }
 350              else if ( $flag == 'no-logfiles' )
 351              {
 352                  $useLogFiles = false;
 353              }
 354              else if ( $flag == 'logfiles' )
 355              {
 356                  $useLogFiles = true;
 357              }
 358              else if ( $flag == 'login' )
 359              {
 360                  $userLogin = $optionData;
 361              }
 362              else if ( $flag == 'password' )
 363              {
 364                  $userPassword = $optionData;
 365              }
 366              else if ( $flag == 'repos' )
 367              {
 368                  $repositoryPath = $optionData;
 369              }
 370              else if ( $flag == 'db-user' )
 371              {
 372                  $dbUser = $optionData;
 373              }
 374              else if ( $flag == 'db-password' )
 375              {
 376                  $dbPassword = $optionData;
 377              }
 378              else if ( $flag == 'db-socket' )
 379              {
 380                  $dbSocket = $optionData;
 381              }
 382              else if ( $flag == 'db-host' )
 383              {
 384                  $dbHost = $optionData;
 385              }
 386              else if ( $flag == 'db-type' )
 387              {
 388                  $dbType = $optionData;
 389              }
 390              else if ( $flag == 'db-name' )
 391              {
 392                  $dbName = $optionData;
 393              }
 394          }
 395          else
 396          {
 397              $flag = substr( $arg, 1, 1 );
 398              $optionData = false;
 399              if ( in_array( $flag, $optionsWithData ) )
 400              {
 401                  if ( strlen( $arg ) > 2 )
 402                  {
 403                      $optionData = substr( $arg, 2 );
 404                  }
 405                  else
 406                  {
 407                      $optionData = $argv[$i+1];
 408                      ++$i;
 409                  }
 410              }
 411              if ( $flag == 'h' )
 412              {
 413                  help();
 414                  exit();
 415              }
 416              else if ( $flag == 'q' )
 417              {
 418                  $isQuiet = true;
 419              }
 420              else if ( $flag == 'c' )
 421              {
 422                  $useColors = true;
 423              }
 424              else if ( $flag == 'd' )
 425              {
 426                  $debugOutput = true;
 427                  if ( strlen( $arg ) > 2 )
 428                  {
 429                      $levels = explode( ',', substr( $arg, 2 ) );
 430                      $allowedDebugLevels = array();
 431                      foreach ( $levels as $level )
 432                      {
 433                          if ( $level == 'all' )
 434                          {
 435                              $useDebugAccumulators = true;
 436                              $allowedDebugLevels = false;
 437                              $useDebugTimingpoints = true;
 438                              break;
 439                          }
 440                          if ( $level == 'accumulator' )
 441                          {
 442                              $useDebugAccumulators = true;
 443                              continue;
 444                          }
 445                          if ( $level == 'timing' )
 446                          {
 447                              $useDebugTimingpoints = true;
 448                              continue;
 449                          }
 450                          if ( $level == 'include' )
 451                          {
 452                              $useIncludeFiles = true;
 453                          }
 454                          if ( $level == 'error' )
 455                              $level = EZ_LEVEL_ERROR;
 456                          else if ( $level == 'warning' )
 457                              $level = EZ_LEVEL_WARNING;
 458                          else if ( $level == 'debug' )
 459                              $level = EZ_LEVEL_DEBUG;
 460                          else if ( $level == 'notice' )
 461                              $level = EZ_LEVEL_NOTICE;
 462                          else if ( $level == 'timing' )
 463                              $level = EZ_LEVEL_TIMING;
 464                          $allowedDebugLevels[] = $level;
 465                      }
 466                  }
 467              }
 468              else if ( $flag == 's' )
 469              {
 470                  changeSiteAccessSetting( $siteaccess, $optionData );
 471              }
 472              else if ( $flag == 'l' )
 473              {
 474                  $userLogin = $optionData;
 475              }
 476              else if ( $flag == 'p' )
 477              {
 478                  $userPassword = $optionData;
 479              }
 480              else if ( $flag == 'r' )
 481              {
 482                  $repositoryPath = $optionData;
 483              }
 484          }
 485      }
 486      else
 487      {
 488          if ( $commandItem['command'] === false )
 489          {
 490              $realCommand = $arg;
 491              // Check for alias
 492              if ( isset( $commandMap[$realCommand] ) )
 493                  $commandItem['command'] = $commandMap[$realCommand];
 494              else
 495                  $commandItem['command'] = $realCommand;
 496              if ( !in_array( $commandItem['command'],
 497                             array( 'help',
 498                                    'create', 'import', 'install', 'export',
 499                                    'add', 'set', 'delete',
 500                                    'list', 'info' ) ) )
 501              {
 502                  help();
 503                  exit( 1 );
 504              }
 505              $readOptions = false;
 506          }
 507          else
 508          {
 509              if ( $commandItem['command'] == 'help' )
 510              {
 511                  $realHelpTopic = $arg;
 512                  // Check for alias
 513                  if ( isset( $commandMap[$realHelpTopic] ) )
 514                      $helpTopic = $commandMap[$realHelpTopic];
 515                  else
 516                      $helpTopic = $realHelpTopic;
 517                  if ( $helpTopic == 'import' )
 518                      helpImport();
 519                  else if ( $helpTopic == 'install' )
 520                      helpInstall();
 521                  else if ( $helpTopic == 'export' )
 522                      helpExport();
 523                  else if ( $helpTopic == 'create' )
 524                      helpCreate();
 525                  else if ( $helpTopic == 'add' )
 526                      helpAdd();
 527                  else if ( $helpTopic == 'set' )
 528                      helpSet();
 529                  else if ( $helpTopic == 'delete' )
 530                      helpDelete();
 531                  else if ( $helpTopic == 'list' )
 532                      helpList();
 533                  else if ( $helpTopic == 'info' )
 534                      helpInfo();
 535                  else
 536                      helpHelp();
 537                  exit();
 538              }
 539              else if ( $commandItem['command'] == 'create' )
 540              {
 541                  if ( $commandItem['name'] === false )
 542                      $commandItem['name'] = $arg;
 543                  else if ( $commandItem['summary'] === false )
 544                      $commandItem['summary'] = $arg;
 545                  else if ( $commandItem['version'] === false )
 546                      $commandItem['version'] = $arg;
 547                  else if ( $commandItem['installtype'] === false )
 548                      $commandItem['installtype'] = strtolower( $arg );
 549              }
 550              else if ( $commandItem['command'] == 'set' )
 551              {
 552                  if ( $commandItem['name'] === false )
 553                      $commandItem['name'] = $arg;
 554                  else if ( $commandItem['attribute'] === false )
 555                      $commandItem['attribute'] = $arg;
 556                  else if ( $commandItem['attribute-value'] === false )
 557                      $commandItem['attribute-value'] = $arg;
 558              }
 559              else if ( $commandItem['command'] == 'add' )
 560              {
 561                  if ( $commandItem['name'] === false )
 562                      $commandItem['name'] = $arg;
 563                  else if ( $commandItem['item'] === false )
 564                      $commandItem['item'] = $arg;
 565                  else
 566                      $commandItem['item-parameters'][] = $arg;
 567              }
 568              else if ( $commandItem['command'] == 'info' )
 569              {
 570                  if ( $commandItem['name'] === false )
 571                      $commandItem['name'] = $arg;
 572                  else if ( $arg[0] == '-' )
 573                  {
 574                      $infoOptions = substr( $arg, 1 );
 575                      if ( preg_match( '#[dfi]#', $infoOptions ) )
 576                      {
 577                          if ( !isset( $commandItem['info-types'] ) )
 578                              $commandItem['info-types'] = array();
 579                          if ( strpos( $infoOptions, 'd' ) !== false )
 580                              $commandItem['info-types'][] = 'dependency';
 581                          if ( strpos( $infoOptions, 'f' ) !== false )
 582                              $commandItem['info-types'][] = 'file';
 583                          if ( strpos( $infoOptions, 'i' ) !== false )
 584                              $commandItem['info-types'][] = 'info';
 585                      }
 586                  }
 587              }
 588              else if ( $commandItem['command'] == 'import' )
 589              {
 590                  if ( $commandItem['name'] === false )
 591                      $commandItem['name'] = $arg;
 592              }
 593              else if ( $commandItem['command'] == 'install' )
 594              {
 595                  if ( $commandItem['name'] === false )
 596                      $commandItem['name'] = $arg;
 597              }
 598              else if ( $commandItem['command'] == 'export' )
 599              {
 600                  if ( $commandItem['name'] === false )
 601                      $commandItem['name'] = $arg;
 602                  else if ( $arg == '-d' )
 603                  {
 604                      ++$i;
 605                      $commandItem['export-directory'] = $argv[$i];
 606                  }
 607              }
 608          }
 609      }
 610  }
 611  $script->setIsQuiet( $isQuiet );
 612  $script->setUseDebugOutput( $debugOutput );
 613  $script->setAllowedDebugLevels( $allowedDebugLevels );
 614  $script->setUseDebugAccumulators( $useDebugAccumulators );
 615  $script->setUseDebugTimingPoints( $useDebugTimingpoints );
 616  $script->setUseIncludeFiles( $useIncludeFiles );
 617  
 618  
 619  appendCommandItem( $commandList, $commandItem );
 620  
 621  // Check all commands
 622  foreach ( $commandList as $commandItem )
 623  {
 624      if ( $commandItem['command'] == 'add' )
 625      {
 626          if ( !$commandItem['name'] and
 627               !$commandItem['item'] )
 628          {
 629              helpAdd();
 630              exit( 1 );
 631          }
 632      }
 633      else if ( $commandItem['command'] == 'set' )
 634      {
 635          if ( !$commandItem['name'] and
 636               !$commandItem['attribute'] and
 637               !$commandItem['attribute-value'] )
 638          {
 639              helpSet();
 640              exit( 1 );
 641          }
 642      }
 643      else if ( $commandItem['command'] == 'create' )
 644      {
 645          if ( !$commandItem['name'] )
 646          {
 647              helpCreate();
 648              exit( 1 );
 649          }
 650      }
 651      else if ( $commandItem['command'] == 'info' )
 652      {
 653          if ( !$commandItem['name'] )
 654          {
 655              helpInfo();
 656              exit( 1 );
 657          }
 658      }
 659      else if ( $commandItem['command'] == 'export' )
 660      {
 661          if ( !$commandItem['name'] )
 662          {
 663              helpExport();
 664              exit( 1 );
 665          }
 666      }
 667      else if ( $commandItem['command'] == 'import' )
 668      {
 669          if ( !$commandItem['name'] )
 670          {
 671              helpImport();
 672              exit( 1 );
 673          }
 674      }
 675      else if ( $commandItem['command'] == 'install' )
 676      {
 677          if ( !$commandItem['name'] )
 678          {
 679              helpInstall();
 680              exit( 1 );
 681          }
 682      }
 683      else if ( in_array( $commandItem['command'],
 684                          array( 'list' ) ) )
 685      {
 686      }
 687      else if ( $commandItem['command'] == 'help' )
 688      {
 689          helpHelp();
 690          exit( 1 );
 691      }
 692      else
 693      {
 694          help();
 695          exit( 1 );
 696      }
 697  }
 698  
 699  if ( $webOutput )
 700      $useColors = true;
 701  
 702  $cli->setUseStyles( $useColors );
 703  $script->setDebugMessage( "\n\n" . str_repeat( '#', 36 ) . $cli->style( 'emphasize' ) . " DEBUG " . $cli->style( 'emphasize-end' )  . str_repeat( '#', 36 ) . "\n" );
 704  
 705  $script->setUseSiteAccess( $siteaccess );
 706  
 707  // Check the database settings and initialize them as current settings
 708  if ( $dbUser !== false or $dbHost !== false or $dbSocket !== false or
 709       $dbType !== false or $dbName !== false )
 710  {
 711      if ( $dbUser === false )
 712      {
 713          $cli->error( "No --db-user specified, cannot connect without a user." );
 714          $script->shutdown( 1 );
 715      }
 716  
 717      if ( $dbType === false )
 718      {
 719          $cli->error( "No --db-type specified, cannot connect without a specific type." );
 720          $script->shutdown( 1 );
 721      }
 722  
 723      $params = array( 'use_defaults' => false,
 724                       'server' => $dbHost,
 725                       'user' => $dbUser,
 726                       'socket' => $dbSocket,
 727                       'password' => $dbPassword,
 728                       'database' => $dbName );
 729      $db =& eZDB::instance( $dbType,
 730                             $params,
 731                             true );
 732  
 733      if ( !$db->isConnected() )
 734      {
 735          $str = "Failed to connnect to database: $dbType://$dbUser@$dbHost";
 736          $cli->error( $str );
 737          $script->shutdown( 1 );
 738      }
 739      eZDB::setInstance( $db );
 740  
 741      // Only continue if the database is using the same version as the PHP code
 742      $rows = $db->arrayQuery( "SELECT * FROM ezsite_data WHERE name = 'ezpublish-version'" );
 743      if ( count( $rows ) > 0 )
 744      {
 745          $version = $rows[0]['value'];
 746          include_once ( 'lib/version.php' );
 747          if ( version_compare( $version, eZPublishSDK::version() ) != 0 )
 748          {
 749              $cli->error( "Version '$version' in database '$dbName' is different from the running version " . eZPublishSDK::version() );
 750              $script->shutdown( 1 );
 751          }
 752      }
 753  }
 754  
 755  $script->setUser( $userLogin, $userPassword );
 756  
 757  $script->initialize();
 758  
 759  include_once ( 'kernel/classes/ezpackage.php' );
 760  
 761  $alreadyCreated = false;
 762  
 763  $createdPackages = array();
 764  
 765  foreach ( $commandList as $commandItem )
 766  {
 767      $command = $commandItem['command'];
 768  
 769      if ( $command == 'list' )
 770      {
 771          $fetchParameters = array();
 772          if ( $repositoryPath )
 773              $fetchParameters['path'] = $repositoryPath;
 774          $packages = eZPackage::fetchPackages( $fetchParameters );
 775          if ( count( $packages ) > 0 )
 776          {
 777              if ( $repositoryPath )
 778                  $cli->output( "The following packages are in the repository " . $cli->stylize( 'dir', $repositoryPath ) . ":" );
 779              else
 780                  $cli->output( "The following packages are in the repository:" );
 781              foreach ( $packages as $package )
 782              {
 783                  $cli->output( $package->attribute( 'name' ) . '-' . $package->attribute( 'version-number' ) . '-' . $package->attribute( 'release-number' ) . ' (' . $cli->stylize( 'emphasize', $package->attribute( 'summary' ) ) . ')' );
 784              }
 785          }
 786          else
 787              $cli->output( "No packages are available in the repository" );
 788      }
 789      else if ( $command == 'info' )
 790      {
 791          if ( isset( $createdPackages[$repositoryPath][$commandItem['name']] ) )
 792              $package =& $createdPackages[$repositoryPath][$commandItem['name']];
 793          else
 794              $package = eZPackage::fetch( $commandItem['name'], $repositoryPath );
 795          if ( $package )
 796          {
 797              $showInfo = false;
 798              $showFiles = false;
 799              $showDependencies = false;
 800              if ( isset( $commandItem['info-types'] ) )
 801              {
 802                  $showInfo = in_array( 'info', $commandItem['info-types'] );
 803                  $showFiles = in_array( 'file', $commandItem['info-types'] );
 804                  $showDependencies = in_array( 'dependency', $commandItem['info-types'] );
 805              }
 806              else
 807                  $showInfo = true;
 808              if ( $showInfo )
 809              {
 810                  $cli->output( "Name        : " . $package->attribute( 'name' ) . str_repeat( ' ', 30 - strlen( $package->attribute( 'name' ) ) ) . "Vendor  : " . $package->attribute( 'vendor' ) );
 811                  $cli->output( "Version     : " . $package->attribute( 'version-number' ) . str_repeat( ' ', 30 - strlen( $package->attribute( 'version-number' ) ) ) . "Source  : " . $package->attribute( 'source' ) );
 812                  $cli->output( "Release     : " . $package->attribute( 'release-number' ) . str_repeat( ' ', 30 - strlen( $package->attribute( 'release-number' ) ) ) . "Licence : " . $package->attribute( 'licence' ) );
 813                  $cli->output( "Summary     : " . $package->attribute( 'summary' ) . str_repeat( ' ', 30 - strlen( $package->attribute( 'summary' ) ) ) . "State   : " . $package->attribute( 'state' ) );
 814                  $cli->output( "eZ publish  : " . $package->attribute( 'ezpublish-named-version' ) .
 815                                " (" . $package->attribute( 'ezpublish-version' ) . ")" );
 816                  $cli->output( "Description : " . $package->attribute( 'description' ) );
 817              }
 818              if ( $showDependencies )
 819              {
 820                  $i = 0;
 821                  foreach ( array( 'provides', 'requires', 'obsoletes', 'conflicts' ) as $dependencySection )
 822                  {
 823                      $dependencyItems = $package->dependencyItems( $dependencySection, false, false, false );
 824                      if ( count( $dependencyItems ) == 0 )
 825                          continue;
 826                      if ( $i > 0 )
 827                          $cli->output();
 828                      $cli->output( $dependencySection . ':' );
 829                      $dependencyTypes = $package->groupDependencyItemsByType( $dependencyItems );
 830                      foreach ( $dependencyTypes as $dependencyTypeName => $dependencyItems )
 831                      {
 832                          foreach ( $dependencyItems as $dependencyItem )
 833                          {
 834                              $dependencyText = $package->createDependencyText( $cli, $dependencyItem, $dependencySection );
 835                              $cli->output( $dependencyText );
 836                          }
 837                      }
 838                      ++$i;
 839                  }
 840              }
 841          }
 842          else
 843              $cli->output( "package " . $commandItem['name'] . " is not in the repository" );
 844      }
 845      else if ( $command == 'add' )
 846      {
 847          if ( isset( $createdPackages[$repositoryPath][$commandItem['name']] ) )
 848              $package =& $createdPackages[$repositoryPath][$commandItem['name']];
 849          else
 850              $package = eZPackage::fetch( $commandItem['name'], $repositoryPath );
 851          if ( $package )
 852          {
 853              $itemType = $commandItem['item'];
 854              switch ( $itemType )
 855              {
 856                  case 'group':
 857                  {
 858                      $groups = $commandItem['item-parameters'];
 859                      if ( count( $groups ) > 0 )
 860                      {
 861                          foreach ( $groups as $group )
 862                          {
 863                              $package->appendGroup( $group );
 864                              if ( !$isQuiet )
 865                                  $cli->notice( "Added to group $group" );
 866                          }
 867                          $package->store();
 868                      }
 869                      else
 870                      {
 871                          $cli->error( "No groups supplied" );
 872                      }
 873                  } break;
 874                  default:
 875                  {
 876                      $handler =& $package->packageHandler( $itemType );
 877                      if ( is_object( $handler ) )
 878                      {
 879                          $realItemType = $handler->handlerType();
 880                          $parameters = $handler->handleAddParameters( $itemType, $package, $cli, $commandItem['item-parameters'] );
 881                          if ( $parameters )
 882                          {
 883                              $handler->add( $itemType, $package, $cli, $parameters );
 884                              $package->store();
 885                          }
 886                          else
 887                          {
 888                              $cli->error( "Failed adding items to package" );
 889                              $script->setExitCode( 1 );
 890                              break 2;
 891                          }
 892                      }
 893                      else
 894                          $cli->error( "Unknown package item type $itemType" );
 895                  } break;
 896              }
 897          }
 898          else
 899              $cli->output( "package " . $commandItem['name'] . " is not in the repository" );
 900      }
 901      else if ( $command == 'set' )
 902      {
 903          $packageAttributes = array( 'summary',
 904                                      'description',
 905                                      'vendor',
 906                                      'priority',
 907                                      'type',
 908                                      'extension',
 909                                      'source',
 910                                      'version',
 911                                      'state' );
 912          if ( !in_array( $commandItem['attribute'], $packageAttributes ) )
 913          {
 914              helpSet();
 915              $script->setExitCode( 1 );
 916          }
 917          else
 918          {
 919              if ( isset( $createdPackages[$repositoryPath][$commandItem['name']] ) )
 920                  $package =& $createdPackages[$repositoryPath][$commandItem['name']];
 921              else
 922                  $package = eZPackage::fetch( $commandItem['name'], $repositoryPath );
 923              if ( $package )
 924              {
 925                  switch ( $commandItem['attribute'] )
 926                  {
 927                      case 'summary':
 928                      case 'description':
 929                      case 'vendor':
 930                      case 'extension':
 931                      case 'source':
 932                      case 'type':
 933                      case 'priority':
 934                      case 'state':
 935                      {
 936                          $package->setAttribute( $commandItem['attribute'], $commandItem['attribute-value'] );
 937                          if ( !$isQuiet )
 938                              $cli->notice( "Attribute " . $cli->style( 'symbol' ) . $commandItem['attribute'] . $cli->style( 'emphasize-end' ) .
 939                                            " was set to " . $cli->style( 'symbol' ) . $commandItem['attribute-value'] . $cli->style( 'emphasize-end' ) );
 940                      } break;
 941                  }
 942                  $package->store();
 943              }
 944              else
 945                  $cli->output( "package " . $commandItem['name'] . " is not in repository" );
 946          }
 947      }
 948      else if ( $command == 'import' or
 949                $command == 'install' )
 950      {
 951          $archiveNames = array();
 952          $archiveName = $commandItem['name'];
 953          $archiveNames[] = $archiveName;
 954          if ( !file_exists( $archiveName ) )
 955          {
 956              $archiveName .= '.' . eZPackage::suffix();
 957              $archiveNames[] = $archiveName;
 958          }
 959          if ( file_exists( $archiveName ) )
 960          {
 961              $package =& eZPackage::import( $archiveName, $commandItem['name'] );
 962  
 963              if ( $package == EZ_PACKAGE_STATUS_ALREADY_EXISTS )
 964              {
 965                  if ( $command == 'install' )
 966                      $cli->notice( "Package " . $cli->stylize( 'emphasize', $archiveName ) . " is already installed " );
 967                  else
 968                      $cli->notice( "Package " . $cli->stylize( 'emphasize', $archiveName ) . " is already imported " );
 969  
 970                  $package = false;
 971              }
 972  
 973              if ( $package )
 974              {
 975                  if ( $command == 'install' )
 976                  {
 977                      $installParameters = array( 'path' => '.' );
 978                      $package->install( $installParameters );
 979                      $cli->notice( "Package " . $cli->stylize( 'emphasize', $package->attribute( 'name' ) ) . " sucessfully installed" );
 980                  }
 981                  else
 982                      $cli->notice( "Package " . $cli->stylize( 'emphasize', $package->attribute( 'name' ) ) . " sucessfully imported" );
 983              }
 984              else
 985              {
 986                  if ( $command == 'install' )
 987                      $cli->error( "Failed installing package $archiveName" );
 988                  else
 989                      $cli->error( "Failed importing package $archiveName" );
 990              }
 991          }
 992          else
 993              $cli->error( "Could not open package " . $commandItem['name'] . ", none of these files were found: " . implode( ',', $archiveNames ) );
 994      }
 995      else if ( $command == 'export' )
 996      {
 997          if ( isset( $createdPackages[$repositoryPath][$commandItem['name']] ) )
 998              $package =& $createdPackages[$repositoryPath][$commandItem['name']];
 999          else
1000              $package = eZPackage::fetch( $commandItem['name'], $repositoryPath );
1001          if ( $package )
1002          {
1003              if ( isset( $commandItem['export-directory'] ) )
1004              {
1005                  $exportDirectory = $commandItem['export-directory'];
1006                  if ( !file_exists( $exportDirectory ) )
1007                  {
1008                      if ( !$isQuiet )
1009                          $cli->notice( "The directory " . $cli->style( 'dir' ) . $exportDirectory . $cli->style( 'dir-end' ) . " does not exist, cannot export package" );
1010                  }
1011                  else
1012                  {
1013                      $package->export( $exportDirectory );
1014                      if ( !$isQuiet )
1015                          $cli->notice( "Package " . $cli->stylize( 'symbol', $package->attribute( 'name' ) ) . " exported to directory " . $cli->stylize( 'dir', $exportDirectory ) );
1016                  }
1017              }
1018              else
1019              {
1020                  $exportPath = $package->archive( $package->exportName() );
1021                  if ( !$isQuiet )
1022                      $cli->notice( "Package " . $cli->stylize( 'symbol', $package->attribute( 'name' ) ) . " exported to file " . $cli->stylize( 'file', $exportPath ) );
1023              }
1024          }
1025          else
1026              $cli->error( "Could not locate package " . $cli->stylize( 'emphasize', $commandItem['name'] ) );
1027      }
1028      else if ( $command == 'create' )
1029      {
1030          if ( $alreadyCreated )
1031              $cli->output();
1032          $package = eZPackage::create( $commandItem['name'],
1033                                         array( 'summary' => $commandItem['summary'] ),
1034                                         $repositoryPath );
1035  
1036          require_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' );
1037          $user =& eZUser::currentUser();
1038          $userObject = $user->attribute( 'contentobject' );
1039  
1040          $commandItem['licence'] = 'GPL';
1041          if ( !in_array( $commandItem['installtype'], array( 'install', 'import' ) ) )
1042              $commandItem['installtype'] = 'install';
1043          if ( !$commandItem['version'] )
1044              $commandItem['version'] = '1.0';
1045  
1046          $package->setRelease( $commandItem['version'], '1', false,
1047                                $commandItem['licence'], 'alpha' );
1048          $package->setAttribute( 'install_type', $commandItem['installtype'] );
1049          if ( $userObject )
1050              $package->appendMaintainer( $userObject->attribute( 'name' ), $user->attribute( 'email' ), 'lead' );
1051          include_once ( 'kernel/classes/ezpackagecreationhandler.php' );
1052          eZPackageCreationHandler::appendLicence( $package );
1053          if ( $userObject )
1054              $package->appendChange( $userObject->attribute( 'name' ), $user->attribute( 'email' ), 'Creation of package' );
1055  
1056          $package->store();
1057          $text = "Created package " . $cli->stylize( 'symbol', $commandItem['name'] ) . "-" . $cli->stylize( 'symbol', $commandItem['version'] );
1058          if ( $commandItem['summary'] )
1059              $text .= " " . $cli->stylize( 'archive', $commandItem['summary'] );
1060          $cli->output( $text );
1061          if ( eZPublishSDK::developmentVersion() !== false )
1062              $cli->warning( "The package will be in development format and can not be installed on a stable eZ publish site" );
1063          $alreadyCreated = true;
1064          $createdPackages[$repositoryPath][$commandItem['name']] =& $package;
1065      }
1066  }
1067  
1068  $cli->output();
1069  
1070  $script->shutdown();
1071  
1072  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7