pwet

Sign in or create your account | Project List | Help | pwet.fr | Planet eZ Publish.fr | Bioutifoul Photos

pwet Svn Source Tree

Root/trunk/www/ezpm.php

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

Archive Download this file

Revision: HEAD