$clusterIdentifier = $clusterMapping[$countryCode];

$application = ApplicationObject::fetchObject(ApplicationObject::definition(), null, array('id' => $appId));
if ($application == null || $application instanceof ApplicationObject == false)
{
    $cli->error("Application with id {$appId} doesn't exist.");
    $script->shutdown(1);
}
$applicationIdentifier = $application->identifier;

$questionCli = new QuestionInteractiveCli();
$replies = array(
    'N' => 'N',
    'Y' => 'Y'
);
$response = $questionCli->askQuestion( "Are you sure you want to remove application {$application->identifier} for country {$countryCode}", $replies);
if ($response == 'N')
{
    $cli->error('Operation aborted by user');
    $script->shutdown(0);
}

removeApplicationFromUserAppBar();
removeApplicationFromCountryAppBar();
removeApplicationFromCountryApplicationLibrary();
removeIcons();
hideFromApplicationLocalized();

$script->shutdown();

/**
/**
 * Asks user about new country code for given country - if it's different, updates it. 
 * @param eZContentObject $country
 * @param QuestionInteractiveCli $cli
 * @return eZContentObject
 */
function interactiveUpdateCountry( $country, $cli )
{
    $countryCode = $country->Name;
    $question = "Specify the new name of the country {$countryCode} (leave empty if the name should not change)";
    $countryCode = $cli->askQuestion( $question, array(
        '/(^$)|(^[a-zA-Z]{2,3}$)/'
    ), 'validateReplyRegex', false );
    if ( $countryCode == '' || $countryCode == $country->Name )
    {
        $countryCode = $country->Name;
    }
    else
    {
        $country = updateCountry( $country, $countryCode );
    }
    return $country;
}
    'nlt'       => 'Newsletter type [news|education]',
    'frq'       => 'Frequency [daily|ẁeekly|monthly]'
) );

$cli = new QuestionInteractiveCli();

$clusterIdentifier  = isset ( $options['cluster'] ) ? $options['cluster'] : false;
$nlType             = isset( $options['nlt'] ) ? $options['nlt'] : null;
$nlFrequency        = isset( $options['frq'] ) ? $options['frq'] : null;

$clusterDomains = eZINI::instance( 'merck.ini' )->variable( 'DomainMappingSettings', 'ClusterDomains' );
if ( !$clusterIdentifier )
{
    $clusters = array_keys( $clusterDomains );
    sort( $clusters );
    $clusterAnswer = $cli->askQuestion( "On which cluster?", $clusters );
    $clusterIdentifier = $clusters[$clusterAnswer];

}
$domain = $clusterDomains[$clusterIdentifier];

$nlTypes = array( 'news', 'education' );
if ( !in_array($nlType, $nlTypes) )
{
    $nlTypeAnswer = $cli->askQuestion( "Which newsletter type?", $nlTypes );
    $nlType = $nlTypes[$nlTypeAnswer];
}

$nlFrequencies = array( 'daily', 'weekly', 'monthly' );
if ( !in_array($nlFrequency, $nlFrequencies) )
{
<?php

if ( !isset($cli) )
    die('This is a eZexec script, please use php bin/php/ezexec.php -s site_admin ' . preg_replace('#^.*/extension/#', 'extension/', __FILE__) . "\n" );

$cli = new QuestionInteractiveCli();
$r = $cli->askQuestion( "This script deletes some class attributes. It must be run AFTER the content has been aligned.\nAre you REALLY sure to proceed? [y/N]", array('#y|n#i'), 'validateReplyRegex', true );
if( strtolower($r) != 'y' )
    $script->shutdown(0, "Bye bye");

$class = eZContentClass::fetchByIdentifier( 'article' );
$classAttributes = $class->fetchAttributes();

$attributesToDelete = array();
foreach( $classAttributes as $classAttribute )
{
    if( $classAttribute->attribute( 'data_type_string') == 'eztags' )
        $attributesToDelete[] = $classAttribute;
}

foreach( $attributesToDelete as $attribute )
{
    $cli->cli->output( $attribute->attribute('identifier').'-'.$attribute->attribute('name') );
}
$r = $cli->askQuestion( "proceed? [y/N]", array('#y|n#i'), 'validateReplyRegex', true );
if( strtolower($r) != 'y')
    $script->shutdown(0, "Bye bye");

$class->removeAttributes( $attributesToDelete );
$cli->cli->output( "Done. You can now run extension/ezscriptmonitor/bin/php/syncobjectattributes.php -s site_admin --classid=".$class->attribute('id'));
function completeUncertainDatas( &$datas )
{
    $cli             = eZCLI::instance();
    $questionHandler = new QuestionInteractiveCli();
    $collisionable   = array ( 'ux_type', 'facet_type', 'hide_empty_values', 'can_be_hidden' );

    foreach ($datas as $key => $facet)
    {
        $f         = $facet['facet'];
        $beggining = "Select the default translation for following facet (Leave empty to specify a custom name):\n";
        $question  = "  > Attribute identifier : {$f['attribute_identifier']}\n";
        $question .= "  > UX type : {$f['ux_type']}\n";
        $question .= "  > Facet type : {$f['facet_type']}\n";
        $question .= "  > Hide empty values : {$f['hide_empty_values']}\n";
        $question .= "  > Can be hidden : {$f['can_be_hidden']}";

        if ($facet['collision'])
        {
            $question.= "\n/!\ There is a collision with another facet using the same attribute identifier:";

            $fb = array();

            if ( isset($datas[$key-1]))
            {
                if ( $datas[$key-1]['facet']['attribute_identifier'] == $f['attribute_identifier'] )
                {
                    $fb[] = $datas[$key-1]['facet'];
                }
            }

            if ( isset($datas[$key+1]))
            {
                if ( $datas[$key+1]['facet']['attribute_identifier'] == $f['attribute_identifier'] )
                {
                    $fb[] = $datas[$key+1]['facet'];
                }
            }

            foreach ( $fb as $fbb )
            {
                foreach ( $collisionable as $col )
                {
                    if ( $f[$col] != $fbb[$col] )
                    {
                        $question .= "\n  > Difference on $col";
                    }
                }
            }

            $question .= "\n>>> Ensure the default translation will be unique";
        }

        $facet['tr'][] = "Other ...";

        $reply = $questionHandler->askQuestion($beggining.$question, $facet['tr'], 'validateReply' );

        if ( $reply == count($facet['tr']) - 1 )
        {
            $beggining = "Enter the default translation for following facet:\n";
            $response  = $questionHandler->askQuestion ($beggining.$question, array(), "validateOpenReply" );
        }
        else
        {
            $response = $facet['tr'][$reply];
        }

        $datas[$key]['reply'] = $response;

        if ($facet['collision'])
        {
            $identifier = $questionHandler->askQuestion ('Enter an identifier for this facet (as it is in collision)', array(), "validateOpenReply" );
        }
        else
        {
            $identifier = $f['attribute_identifier'];
            $cli->notice("No collision, the new identifier will be the attribute identifier : $identifier");
        }

        $datas[$key]['identifier'] = $identifier;

        unset($datas[$key]['tr']);
    }
}
    $newId = $mappingKeyWithNewID[$key];
    $sql = sprintf('UPDATE content_has_taxonomy SET new_taxonomy_id = %s WHERE taxonomy_id = %s;', $newId, $id);
    if ( $apply )
    {
        XMLImportDB::query($sql);
    }
}



if ( $apply && $tmpColumnExist )
{
    $qCli = new QuestionInteractiveCli();
    $switchTable = $qCli->askQuestion('Switch actual column by the temporary column', array(
        'Y' => 'New values replace the old and old value are maintained in a new column',
        'N' => 'Do nothing : old values are maintained and the new value remain in the temporary column'
    ));

    if ( $switchTable == 'Y' )
    {
        $cli->notice('Swith columns...');
        $sql = '
            ALTER TABLE content_has_taxonomy
            DROP PRIMARY KEY,
            DROP FOREIGN KEY fk_article_has_taxonomy_taxonomy1,
            CHANGE taxonomy_id old_taxonomy_id INT(11) NOT NULL,
            CHANGE new_taxonomy_id taxonomy_id INT(11) NOT NULL,
            ADD PRIMARY KEY(content_id, taxonomy_id);';

        $cli->notice('You must execute manually : ' . PHP_EOL . $sql);
    }
function addCategory($clusterIdentifier, $category)
{
    $db              = eZDB::instance();
    $questionHandler = new QuestionInteractiveCli();
    $question        = "Create new category $category";
    $possibleReplies = array ( "Y" => "Yes", "N" => "No" );
    $response        = $questionHandler->askQuestion( $question, $possibleReplies );
    
    if ( $response == "N" )
    {
        return false;
    }
    else
    {
        $articleClass      = eZContentClass::fetchByIdentifier("article");
        $articleAttributes = $articleClass->fetchAttributes( false, false );
        $question          = "Associate $category to attribute";
        $possibleReplies   = array();

        foreach ( $articleAttributes as $attribute )
        {
            $possibleReplies[] = $attribute['identifier'];
        }

        $responseAttribute = $questionHandler->askQuestion( $question, $possibleReplies );

        $attributeName = $possibleReplies[$responseAttribute];

        // is_mdm set to 0
        $queryLast     = "SELECT max(id) as new_id from mm_taxonomy_category";
        $result        = $db->arrayQuery( $queryLast );
        $newCategoryId = $result[0]['new_id'] + 1;

        $queryInsert = sprintf(
            'INSERT INTO mm_taxonomy_category VALUES (%u,"%s","%s", 0)',
            $newCategoryId,
            $category,
            $attributeName
        );

        $db->query( $queryInsert );

        return $newCategoryId;
    }
}