Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All subsequent calls now uses ezpublish/console if applicable. #134

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 59 additions & 17 deletions bin/php/updatesearchindexsolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function run()
'clean-all' => "Remove all search data for all installations",
'conc' => 'Parallelization, number of concurent processes to use',
'php-exec' => 'Full path to PHP executable',
'console-exec' => 'Full path to eZ5 console.',
'commit-within' => 'Commit to Solr within this time in seconds (default '
. self::DEFAULT_COMMIT_WITHIN . ' seconds)',
'offset' => '*For internal use only*',
Expand Down Expand Up @@ -161,8 +162,15 @@ public function run()
{
$this->CLI->output( 'Starting object re-indexing' );

// Get PHP executable from user.
$this->getPHPExecutable();
global $input;

if (is_null($input)) {
$this->getPHPExecutable(); // Get PHP executable from user.
}
else {
$this->getConsoleExecutable($input);
}


$this->runMain();
}
Expand Down Expand Up @@ -233,28 +241,61 @@ protected function runSubProcess( $nodeID, $offset, $limit )
$this->Script->shutdown( 0 );
}

/**
* This script is being executed as a legacy-script from eZ5.
*/
protected function getConsoleExecutable($input)
{
$output = array();
$exec = '../ezpublish/console';

if ( !empty($this->Options['console-exec']) )
{
$exec = $this->Options['console-exec'];
}

exec($exec, $output);

while( !$this->validateExecutable($output, 'Symfony') )
{
$input = readline( 'Enter path to Console executable ( or [q] to quit )' );
if ( $input === 'q' )
{
$this->Script->shutdown( 0 );
}

exec( $input, $output );
}

$parts = array($exec);

if ($input->hasOption('env'))
{
$parts[] = '--env=' . $input->getOption('env');
}

$parts[] = $input->getArgument('command');

$this->Executable = implode(' ', $parts);
}

/**
* Get PHP executable from user input. Exit if php executable cannot be
* found and if no executable is entered.
*/
protected function getPHPExecutable()
{
$validExecutable = false;
$output = array();
$exec = 'php';

if ( !empty( $this->Options['php-exec'] ) )
{
$exec = $this->Options['php-exec'];
}
exec( $exec . ' -v', $output );

if ( count( $output ) && strpos( $output[0], 'PHP' ) !== false )
{
$validExecutable = true;
$this->Executable = $exec;
}
exec( $exec . ' -v', $output );

while( !$validExecutable )
while( !$this->validateExecutable($output, 'PHP') )
{
$input = readline( 'Enter path to PHP-CLI executable ( or [q] to quit )' );
if ( $input === 'q' )
Expand All @@ -263,13 +304,14 @@ protected function getPHPExecutable()
}

exec( $input . ' -v', $output );

if ( count( $output ) && strpos( $output[0], 'PHP' ) !== false )
{
$validExecutable = true;
$this->Executable = $input;
}
}

$this->Executable = $exec;
}

protected function validateExecutable($output, $string)
{
return count($output) && strpos ( $output[0], $string ) !== false;
}

/**
Expand Down Expand Up @@ -491,7 +533,7 @@ protected function execute( $nodeID, $offset, $limit, $isSubProcess = false )

if ( $this->Options['siteaccess'] )
{
$paramString .= ' -s ' . escapeshellarg( $this->Options['siteaccess'] );
$paramString .= ' --siteaccess=' . $this->Options['siteaccess'];
}

$paramString .=
Expand Down