Degrades the main language to normal language

@throws \Exception
@return boolean

@api
544250
protected function resetMain()
    {
        try {
            $language = $this->languageRepository->mainLanguage();
            if (null !== $language) {
                $result = $this->languageRepository
                            ->setRepositoryObject($language)
                            ->save(array('MainLanguage' => 0));

                return $result;
            }

            return true;
        } catch (\Exception $e) {
            if (isset($this->languageRepository) && $this->languageRepository !== null) {
                $this->languageRepository->rollBack();
            }

            throw $e;
        }
    }
1015453
protected function translateDelete()
    {
        $build = 'delete from ' . $this->escapeTable(false);

        // build the where statements
        if ($wheres = $this->attr('wheres'))
        {
            $build .= $this->translateWhere($wheres);
        }
    
        // build offset and limit
        if ($this->attr('limit'))
        {
             $build .= $this->translateLimit();
        }

        return $build;
    }
133809
public static function cacheFlush()
    {
        foreach ( self::getCategories() as $category ) {
            foreach ( Yii::$app->i18n->languages as $language ) {
                Yii::$app->cache->delete([
                    'yii\i18n\DbMessageSource',
                    $category,
                    $language,
                ]);
            }
        }

        return true;
    }
1120229
public function convert()
    {
        //Cache result if you want to run it multiple times
        if (!empty($this->output))
        {
            return $this->output;
        }

        if (empty($this->data))
        {
            throw new \Exception("No data specified!");
        }

        $this->output = '<?xml version="' . static::XML_VERSION . '" encoding="' . static::XML_ENCODING . '"?>' . PHP_EOL;

        $this->convertNodeToXML($this->data, $this->rootNode, 0);

        $this->output = trim($this->output);

        return $this->output;
    }
425609
public function delete()
    {
        if (null === $this->alLanguage) {
            throw new General\ArgumentIsEmptyException('exception_no_languages_selected_delete_skipped');
        }

        if ($this->alLanguage->getMainLanguage() == 1) {
            throw new LanguageException\RemoveMainLanguageException('exception_website_main_languages_cannot_be_delete');
        }

        $this->dispatchBeforeOperationEvent(
                '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Language\BeforeLanguageDeletingEvent',
                LanguageEvents::BEFORE_DELETE_LANGUAGE,
                array(),
                'exception_language_deleting_aborted'
        );

        try {
            $this->languageRepository->startTransaction();
            $result = $this->languageRepository
                            ->setRepositoryObject($this->alLanguage)
                            ->delete();

            if ($result) {
                $eventName = LanguageEvents::BEFORE_DELETE_LANGUAGE_COMMIT;
                $result = !$this->eventsHandler
                                ->createEvent($eventName, '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Language\BeforeDeleteLanguageCommitEvent', array($this, array()))
                                ->dispatch()
                                ->getEvent($eventName)
                                ->isAborted();
            }

            if (false !== $result) {
                $this->languageRepository->commit();

                $this->eventsHandler
                     ->createEvent(LanguageEvents::AFTER_DELETE_LANGUAGE, '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Language\AfterLanguageDeletedEvent', array($this))
                     ->dispatch();

                return $result;
            }

            $this->languageRepository->rollBack();

            return $result;
        } catch (\Exception $e) {
            if (isset($this->languageRepository) && $this->languageRepository !== null) {
                $this->languageRepository->rollBack();
            }

            throw $e;
        }
    }
906541
public function actionDelete()
    {
        
        $this->outVerbose("Deleting language '" . $this->options['language'] . "' for extension '" . $this->options['extension'] . "' ...");
    	
    	$dir = $this->buildLanguagePath($this->options['extension'], $this->options['language']);
        if (!tao_helpers_File::remove($dir, true)) {
        	$this->err("Could not delete language '" . $this->options['language'] . "' for extension '" . $this->options['extension'] . "'.", true);	
        }
        
        $this->outVerbose("Language '" . $this->options['language'] . "' for extension '" . $this->options['extension'] . "' successfully deleted.");
        
    }
1150464
public function remove()
    {
        //dallocate shared memory
        if (!shm_remove($this->shm)) {
            return false;
        }
        $this->dettach();
        // shm_remove maybe not working. it likes a php bug.
        unset($this->shm);

        return true;
    }
653387
public function detectLanguage()
    {
        $acceptableLanguages = Yii::$app->getRequest()->getAcceptableLanguages();
        foreach ($acceptableLanguages as $language) {
            if ($this->isValidLanguage($language)) {
                return $language;
            }
        }
        foreach ($acceptableLanguages as $language) {
            $pattern = preg_quote(substr($language, 0, 2), '/');
            foreach ($this->languages as $key => $value) {
                if (preg_match('/^' . $pattern . '/', $value) || preg_match('/^' . $pattern . '/', $key)) {
                    return $this->isValidLanguage($key) ? $key : $value;
                }
            }
        }

        return false;
    }
791029
public function badWords()
    {
        $words = explode(' ', $this->text);

        return collect($this->dictionary)->filter(function ($value) use ($words) {
            if ($this->strict) {
                return str_contains(strtolower($this->text), strtolower($value['word']));
            }

            return in_array(strtolower($value['word']), $words);
        })->map(function ($value) {
            return [
                'language' => $value['language'],
                'word'     => strtolower($value['word']),
            ];
        })->toArray();
    }
548545
protected function checkIfNoLanguageFallback()
    {
        $tsfe = self::getTsfe();
        // Check if we have fallen back to a default language
        if (GeneralUtility::getLanguageId() !== $tsfe->sys_language_uid) {
            return false; //don't index untranslated page
        }
        return true;
    }
655018
protected function restoreLanguage()
    {
        // Switch back to the original FE language to not disturb the frontend.
        if ($this->getMetaModel()->getActiveLanguage() != $GLOBALS['TL_LANGUAGE']) {
            $event = new LoadLanguageFileEvent('countries', null, true);
            $this->eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $event);
        }
    }
895320
public function uninstall_language($lang) {
        global $CFG;

        $dest1 = $CFG->dataroot.'/lang/'.$lang;
        $dest2 = $CFG->dirroot.'/lang/'.$lang;
        $rm1 = false;
        $rm2 = false;
        if (file_exists($dest1)) {
            $rm1 = remove_dir($dest1);
        }
        if (file_exists($dest2)) {
            $rm2 = remove_dir($dest2);
        }

        if ($rm1 or $rm2) {
            $this->info[] = get_string('langpackremoved', 'tool_langimport', $lang);
            event\langpack_removed::event_with_langcode($lang)->trigger();
            return true;
        } else {    // Nothing deleted, possibly due to permission error.
            $this->errors[] = get_string('langpacknotremoved', 'tool_langimport', $lang);
            return false;
        }
    }
1156253
public function reverse()
    {
        return static::of(
            ArrayList::of($this->split())->reverse()->join(),
            $this->encoding
        );
    }
793693
public function cmdDeleteLanguage()
    {
        $id = $this->getParam(0);
        $all = $this->getParam('all');

        if (!isset($id) && empty($all)) {
            $this->errorAndExit($this->text('Invalid command'));
        }

        $result = false;

        if (isset($id)) {
            $result = $this->language->delete($id);
        } else if (!empty($all)) {

            $deleted = $count = 0;

            foreach ($this->language->getList(array('in_database' => true)) as $language) {
                $count++;
                $deleted += (int) $this->language->delete($language['code']);
            }

            $result = $count && $count == $deleted;
        }

        if (empty($result)) {
            $this->errorAndExit($this->text('Unexpected result'));
        }

        $this->output();
    }
941922
public function delete()
    {
        // convert to condition.
        $args = func_get_args();
        $cond = call_user_func_array(array($this, 'toCondition'), $args);

        // to SQL.
        $sql = $cond->toDeleteSQL();
        var_dump($sql, $cond->getParams());

        // query.
        $sth = $this->query($sql, $cond->getParams());
        return $sth->isSuccess();
    }
737035
public function updateTranslations()
    {
        $this->translations_list->iterate(
            function ($key, $nb_translation)
            {
                return $nb_translation->save();
            }
        );

        $this->translations_removed->iterate(
            function ($key, $nb_translation)
            {
                return $nb_translation->delete();
            }
        );
        $this->translations_removed->clear();
    }
1238086
public function bootstrap()
    {
        $languageRepository = $this->languageManager->getLanguageRepository();
        $pageRepository = $this->pageManager->getPageRepository();
        $blockRepository = $this->blockManager->getBlockRepository();

        $languageRepository->startTransaction();
        if ( ! $this->removeActiveLanguages($languageRepository)) {
            return $this->fails($languageRepository);
        }

        if ( ! $this->removeActivePages($pageRepository)) {
            return $this->fails($languageRepository);
        }

        $blockRepository->deleteBlocks(1, 1, true);

        if ( ! $this->addLanguage()) {
            return $this->fails($languageRepository);
        }

        if ( ! $this->addPage()) {
            return $this->fails($languageRepository);
        }

        $languageRepository->commit();

        return true;
    }