/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $this->writeCommandHeader($output, 'Current mail configuration.'); $path = $this->getHelper('configuration')->getConfigurationPath(); $path .= 'mail.conf.php'; define('IS_WINDOWS_OS', strtolower(substr(php_uname(), 0, 3)) == 'win' ? true : false); if (isset($path) && is_file($path)) { $output->writeln('File: ' . $path); $lines = file($path); $list = array('SMTP_HOST', 'SMTP_PORT', 'SMTP_MAILER', 'SMTP_AUTH', 'SMTP_USER', 'SMTP_PASS'); foreach ($lines as $line) { $match = array(); if (preg_match("/platform_email\\['(.*)'\\]/", $line, $match)) { if (in_array($match[1], $list)) { eval($line); } } } $output->writeln('Host: ' . $platform_email['SMTP_HOST']); $output->writeln('Port: ' . $platform_email['SMTP_PORT']); $output->writeln('Mailer: ' . $platform_email['SMTP_MAILER']); $output->writeln('Auth SMTP:' . $platform_email['SMTP_AUTH']); $output->writeln('User: '******'SMTP_USER']); $output->writeln('Pass: '******'SMTP_PASS']); } else { $output->writeln("<comment>Nothing to print</comment>"); } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $dialog = $this->getHelperSet()->get('dialog'); if (!$dialog->askConfirmation($output, '<question>Are you sure you want to drop all database in this portal? (y/N)</question>', false)) { return; } if (!$dialog->askConfirmation($output, '<question>Are you really sure? (y/N)</question>', false)) { return; } $_configuration = $this->getConfigurationArray(); $connection = $this->getConfigurationHelper()->getConnection(); // $configurationFilePath = $this->getConfigurationHelper()->getConfigurationFilePath(); // $output->writeln("<comment>Reading configuration file:</comment> <info>$configurationFilePath</info>"); if ($connection) { $cmd = 'mysql -h ' . $_configuration['db_host'] . ' -u ' . $_configuration['db_user'] . ' -p' . $_configuration['db_password'] . ' -e "DROP DATABASE %s"'; $list = $_configuration = $this->getHelper('configuration')->getAllDatabases(); if (is_array($list)) { $output->writeln('<comment>Starting Chamilo drop database process.</comment>'); foreach ($list as $db) { $c = sprintf($cmd, $db); $output->writeln("Dropping DB: {$db}"); $err = @system($c); } $output->writeln('<comment>End drop database process.</comment>'); } } else { $output->writeln("<comment>Can't established connection with the database. Probably it was already deleted.</comment>"); } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $output->writeln('Starting Chamilo SQL cli'); $_configuration = $this->getConfigurationArray(); $cmd = 'mysql -h ' . $_configuration['db_host'] . ' -u ' . $_configuration['db_user'] . ' -p' . $_configuration['db_password'] . ' ' . $_configuration['main_database']; $process = proc_open($cmd, array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes); $proc_status = proc_get_status($process); $exit_code = proc_close($process); return $proc_status["running"] ? $exit_code : $proc_status["exitcode"]; /*$output->writeln('<comment>Starting Chamilo process</comment>'); $output->writeln('<info>Chamilo process ended succesfully</info>'); */ /* $progress = $this->getHelperSet()->get('progress'); $progress->start($output, 50); $i = 0; while ($i++ < 50) { // ... do some work // advance the progress bar 1 unit $progress->advance(); } $progress->finish();*/ // Inside execute function //$output->getFormatter()->setStyle('fcbarcelona', new OutputFormatterStyle('red', 'blue', array('blink', 'bold', 'underscore'))); //$output->writeln('<fcbarcelona>Messi for the win</fcbarcelona>'); }
/** * @param InputInterface $input * @param OutputInterface $output * @return bool|int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $files = $this->getConfigurationHelper()->getDeletedDocuments(); if ($input->isInteractive()) { $this->writeCommandHeader($output, 'Cleaning deleted documents.'); $list = $input->getOption('list'); //1 if the option was set if ($list) { if (count($files) > 0) { foreach ($files as $file) { $output->writeln($file->getRealpath()); } } else { $output->writeln('No file to be deleted in courses/ directory'); return; } } $stats = $input->getOption('size'); //1 if the option was set if ($stats) { $size = 0; foreach ($files as $file) { $size += $file->getSize(); } $output->writeln('Total size used by deleted documents: ' . round((double) $size / 1024 / 1024, 2) . 'MB'); } $dialog = $this->getHelperSet()->get('dialog'); if (!$dialog->askConfirmation($output, '<question>Are you sure you want to clean the Chamilo deleted documents? (y/N)</question>', false)) { return; } } $this->removeFiles($files, $output); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $_configuration = $this->getHelper('configuration')->getConfiguration(); $dbh = $this->getHelper('configuration')->getConnection(); $lang = mysql_real_escape_string($input->getArgument('language')); $ls = "SELECT id, english_name, available FROM language WHERE english_name = '{$lang}'"; $lq = mysql_query($ls); if ($lq === false) { $output->writeln('Error in query: ' . mysql_error()); return null; } $num = mysql_num_rows($lq); if ($num < 1) { $output->writeln($lang . ' language not found in the database. Please make sure you use an existing language name.'); return null; } $lr = mysql_fetch_assoc($lq); if ($lr['available'] == 0) { $output->writeln($lang . ' language is already disabled. Nothing to do.'); return null; } // Everything is OK so far, enable the language $us = "UPDATE language SET available = 0 WHERE id = {$lr['id']}"; $uq = mysql_query($us); if ($uq === false) { $output->writeln('Error in query: ' . mysql_error()); } else { $output->writeln($lang . ' language has been disabled.'); } return null; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $_configuration = $this->getConfigurationArray(); $dump = 'mysqldump -h ' . $_configuration['db_host'] . ' -u ' . $_configuration['db_user'] . ' -p' . $_configuration['db_password'] . ' ' . $_configuration['main_database']; system($dump); return null; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $this->writeCommandHeader($output, 'Generating temp folders.'); // Data folders $files = $this->getConfigurationHelper()->getTempFolderList(); $this->createFolders($output, $files, 0777); }
/** * @param InputInterface $input * @param OutputInterface $output * @return bool|int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $this->writeCommandHeader($output, 'Cleaning data folders.'); $dialog = $this->getHelperSet()->get('dialog'); if (!$dialog->askConfirmation($output, '<question>Are you sure you want to clean the Chamilo data files? (y/N)</question>', false)) { return; } $files = $this->getConfigurationHelper()->getDataFiles(); $this->removeFiles($files, $output); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $language = $input->getArgument('language'); $tmpFolder = $input->getOption('tmp'); $_configuration = $this->getHelper('configuration')->getConfiguration(); $connection = $this->getHelper('configuration')->getConnection(); if ($connection) { $lang = isset($language) ? $language : null; $lang = mysql_real_escape_string($lang); $q = mysql_query("SELECT * FROM language WHERE english_name = '{$lang}' "); $langInfo = mysql_fetch_array($q, MYSQL_ASSOC); if (!$langInfo) { $output->writeln("<comment>Language '{$lang}' is not registered in the Chamilo Database</comment>"); $q = mysql_query("SELECT * FROM language WHERE parent_id IS NULL or parent_id = 0"); $output->writeln("<comment>Available languages are: </comment>"); while ($langRow = mysql_fetch_array($q, MYSQL_ASSOC)) { $output->write($langRow['english_name'] . ", "); } $output->writeln(' '); $q = mysql_query("SELECT * FROM language WHERE parent_id <> 0"); $output->writeln("<comment>Available sub languages are: </comment>"); while ($langRow = mysql_fetch_array($q, MYSQL_ASSOC)) { $output->write($langRow['english_name'] . ", "); } $output->writeln(' '); exit; } else { $output->writeln("<comment>Language</comment> <info>'{$lang}'</info> <comment>is registered in the Chamilo installation with iso code: </comment><info>{$langInfo['isocode']} </info>"); } $langFolder = $_configuration['root_sys'] . 'main/lang/' . $lang; if (!is_dir($langFolder)) { $output->writeln("<comment>Language '{$lang}' does not exist in the path: {$langFolder}</comment>"); } if (empty($tmpFolder)) { $tmpFolder = '/tmp/'; $output->writeln("<comment>No temporary directory defined. Assuming /tmp/. Please make sure you have *enough space* left on that device"); } if (!is_dir($tmpFolder)) { $output->writeln("<comment>Temporary directory: {$tmpFolder} is not a valid dir path, using /tmp/ </comment>"); $tmpFolder = '/tmp/'; } if ($langInfo) { $output->writeln("<comment>Creating translation package</comment>"); $fileName = $tmpFolder . $langInfo['english_name'] . '.tar'; $phar = new \PharData($fileName); $phar->buildFromDirectory($langFolder); $phar->setMetadata($langInfo); $output->writeln("<comment>File created:</comment> <info>{$fileName}</info>"); } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $dumpPath = $input->getArgument('file'); if (!is_dir($dumpPath) && file_exists($dumpPath)) { $_configuration = $this->getConfigurationArray(); $output->writeln('<comment>Starting restoring database</comment>'); $action = 'mysql -h ' . $_configuration['db_host'] . ' -u ' . $_configuration['db_user'] . ' -p' . $_configuration['db_password'] . ' ' . $_configuration['main_database'] . ' < ' . $dumpPath; system($action); $output->writeln('<info>Process ended succesfully</info>'); } else { $output->writeln('<comment>File is not a valid SQL file: ' . $dumpPath . ' </comment>'); } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $_configuration = $this->getHelper('configuration')->getConfiguration(); $dbh = $this->getHelper('configuration')->getConnection(); $parent = mysql_real_escape_string($input->getArgument('parent')); $lang = mysql_real_escape_string($input->getArgument('sublanguage')); $ls = "SELECT english_name FROM language WHERE english_name = '{$lang}'"; $lq = mysql_query($ls); if ($lq === false) { $output->writeln('Error in query: ' . mysql_error()); return null; } $num = mysql_num_rows($lq); if ($num > 0) { $output->writeln($lang . ' already exists in the database. Pick another English name.'); return null; } $ls = "SELECT id, original_name, english_name, isocode, dokeos_folder FROM language WHERE english_name = '{$parent}'"; $lq = mysql_query($ls); if ($lq === false) { $output->writeln('Error in query: ' . mysql_error()); return null; } $num = mysql_num_rows($lq); if ($num < 1) { $output->writeln('The parent language ' . $parent . ' does not exist. Please choose a valid parent.'); return null; } if (is_dir($_configuration['root_sys'] . 'main/lang/' . $lang)) { $output->writeln('The destination directory (' . $_configuration['root_sys'] . 'main/lang/' . $lang . ') already exists. Please choose another sub-language name.'); return null; } // Everything is OK so far, insert the sub-language $lr = mysql_fetch_assoc($lq); $is = "INSERT INTO language (original_name, english_name, isocode, dokeos_folder, available, parent_id) VALUES ('{$lr['original_name']}-2','{$lang}','{$lr['isocode']}','{$lang}',0,{$lr['id']})"; $iq = mysql_query($is); if ($iq === false) { $output->writeln('Error in query: ' . mysql_error()); } else { //permissions gathering, copied from main_api.lib.php::api_get_permissions_for_new_directories() //require_once $_configuration['root_sys'].'main/inc/lib/main_api.lib.php'; //$perm = api_get_permissions_for_new_directories(); // @todo Improve permissions to force creating as user www-data $r = @mkdir($_configuration['root_sys'] . 'main/lang/' . $lang, 0777); $output->writeln('Sub-language ' . $lang . ' of language ' . $parent . ' has been created but is disabled. Fill it, then enable to make available to users. Make sure you check the permissions for the newly created directory as well (' . $_configuration['root_sys'] . 'main/lang/' . $lang . ')'); } return null; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $dialog = $this->getHelperSet()->get('dialog'); if (!$dialog->askConfirmation($output, '<question>Are you sure you want to show the database connection info here? (y/N)</question>', false)) { return; } $_configuration = $this->getConfigurationArray(); $output->writeln("Database connection details:"); $output->writeln("Host:\t" . $_configuration['db_host']); $output->writeln("User:\t" . $_configuration['db_user']); $output->writeln("Pass:\t" . $_configuration['db_password']); $output->writeln("DB:\t" . $_configuration['main_database']); $output->writeln("Connection string (add password manually for increased security:"); $output->writeln("mysql -h " . $_configuration['db_host'] . " -u " . $_configuration['db_user'] . " -p " . $_configuration['main_database'] . "\n"); }
/** * @todo use doctrine * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $table = $input->getArgument('table'); $_configuration = $this->getConfigurationArray(); $connection = $this->getConfigurationHelper()->getConnection(); $t = mysql_real_escape_string($table); $q = mysql_query('SELECT COUNT(*) FROM ' . $t); if ($q !== false) { $r = mysql_fetch_row($q); $n = $r[0]; $output->writeln('<comment>Database/table/number of rows: </comment><info>' . $_configuration['main_database'] . '/' . $t . '/' . $n . '</info>'); } else { $output->writeln("<comment>Table '{$table}' does not exists in the database: " . $_configuration['main_database']); } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $_configuration = $this->getHelper('configuration')->getConfiguration(); $dbh = $this->getHelper('configuration')->getConnection(); $av = mysql_real_escape_string($input->getArgument('availability')); $current = 'english'; $ls = "SELECT selected_value FROM settings_current WHERE variable='platformLanguage'"; $lq = mysql_query($ls); if ($lq === false) { $output->writeln('Error in query: ' . mysql_error()); return null; } else { $lr = mysql_fetch_assoc($lq); //$output->writeln('Current default language is: '.$lr['selected_value']); $current = $lr['selected_value']; } $where = ''; if ($av === '0') { $where = 'WHERE available = 0'; } elseif ($av === '1') { $where = 'WHERE available = 1'; } $ls = "SELECT english_name, available FROM language " . $where . " ORDER BY english_name"; $lq = mysql_query($ls); if ($lq === false) { $output->writeln('Error in query: ' . mysql_error()); return null; } else { $languages = array(); $output->writeln("Language | Enabled | Platform language"); $output->writeln("-----------------------------------------------"); while ($lr = mysql_fetch_assoc($lq)) { $pl = ''; $l = strlen($lr['english_name']); if ($lr['english_name'] == $current) { $pl = '*'; } $output->writeln($lr['english_name'] . str_repeat(' ', 18 - $l) . "| " . $lr['available'] . " | " . $pl); } } return null; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $_configuration = $this->getHelper('configuration')->getConfiguration(); $dbh = $this->getHelper('configuration')->getConnection(); $lang = mysql_real_escape_string($input->getArgument('language')); if (empty($lang)) { $ls = "SELECT selected_value FROM settings_current WHERE variable='platformLanguage'"; $lq = mysql_query($ls); if ($lq === false) { $output->writeln('Error in query: ' . mysql_error()); return null; } else { $lr = mysql_fetch_assoc($lq); $output->writeln('Current default language is: ' . $lr['selected_value']); } } else { $ls = "SELECT english_name FROM language ORDER BY english_name"; $lq = mysql_query($ls); if ($lq === false) { $output->writeln('Error in query: ' . mysql_error()); return null; } else { $languages = array(); while ($lr = mysql_fetch_assoc($lq)) { $languages[] = $lr['english_name']; } if (!in_array($lang, $languages)) { $output->writeln($lang . ' must be available on your platform before you can set it as default'); return null; } $lu = "UPDATE settings_current set selected_value = '{$lang}' WHERE variable = 'platformLanguage'"; $lq = mysql_query($lu); if ($lq === false) { $output->writeln('Error in query: ' . mysql_error()); } else { $output->writeln('Language set to ' . $lang); } } } return null; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $this->writeCommandHeader($output, 'Setting permissions ...'); $linuxUser = $input->getOption('linux-user'); $linuxGroup = $input->getOption('linux-group'); // All files $files = $this->getConfigurationHelper()->getSysFolders(); $this->setPermissions($output, $files, 0777, $linuxUser, $linuxGroup, false); $files = $this->getConfigurationHelper()->getSysFiles(); $this->setPermissions($output, $files, null, $linuxUser, $linuxGroup, false); // Data folders $files = $this->getConfigurationHelper()->getDataFolders(); $this->setPermissions($output, $files, 0777, $linuxUser, $linuxGroup); // Config folders $files = $this->getConfigurationHelper()->getConfigFolders(); $this->setPermissions($output, $files, 0555, $linuxUser, $linuxGroup); $files = $this->getConfigurationHelper()->getConfigFiles(); $this->setPermissions($output, $files, 0555, $linuxUser, $linuxGroup); // Temp folders $files = $this->getConfigurationHelper()->getTempFolders(); $this->setPermissions($output, $files, 0777, $linuxUser, $linuxGroup); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $_configuration = $this->getHelper('configuration')->getConfiguration(); $resultPath = $input->getArgument('result'); $tmpFolder = $input->getOption('tmp'); if (empty($tmpFolder)) { $output->writeln('<info>No temporary directory defined. Assuming /tmp/. Please make sure you have *enough space* left on that device</info>'); $tmpFolder = '/tmp'; } $deleteTemp = $input->getOption('del-archive'); if ($deleteTemp) { //Calling command $command = $this->getApplication()->find('files:clean_temp_folder'); $arguments = array('command' => 'files:clean_temp_folder'); $input = new ArrayInput($arguments); $command->run($input, $output); } else { $output->writeln('<comment>Temp archives are not removed</comment>'); } $cha_dir = realpath($_configuration['root_sys']); $output->writeln('<comment>Starting full backup</comment>'); $f = $_configuration['db_user']; //backup the files (this requires root permissions) $bkp_dir = $tmpFolder . '/' . $f . '-' . date('Ymdhis'); $err = @mkdir($bkp_dir); $tgz = $bkp_dir . '/' . $f . '.tgz'; $sql = $bkp_dir . '/' . $f . '-db.sql'; $err = @system('tar zcf ' . $tgz . ' ' . $cha_dir); $output->writeln('<comment>Generating mysqldump</comment>'); $err = @system('mysqldump -h ' . $_configuration['db_host'] . ' -u ' . $_configuration['db_user'] . ' -p' . $_configuration['db_password'] . ' ' . $_configuration['main_database'] . ' --result-file=' . $sql); $output->writeln('<comment>Generating tarball </comment>'); $err = @system('tar zcf ' . $resultPath . ' ' . $bkp_dir); $err = @system('rm -rf ' . $bkp_dir); $output->writeln('<comment>End Chamilo backup. File can be found here: ' . realpath($resultPath) . ' </comment>'); }
/** * @param InputInterface $input * @param OutputInterface $output * @return bool|int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); if ($input->isInteractive()) { $this->writeCommandHeader($output, 'Looking for videos...'); $confPath = $this->getConfigurationHelper()->getConfigurationFilePath(); $sysPath = $this->getConfigurationHelper()->getSysPathFromConfigurationFile($confPath); $dir = $input->getArgument('source'); //1 if the option was set if (substr($dir, 0, 1) != '/') { $dir = $sysPath . $dir; } if (!is_dir($dir)) { $output->writeln($dir . ' was not confirmed as a directory (if not starting with /, it is considered as relative to Chamilo\'s root folder)'); return; } $this->ext = $input->getOption('ext'); if (empty($this->ext)) { $this->ext = 'webm'; } $this->origExt = $input->getOption('orig-ext'); if (empty($this->origExt)) { $this->origExt = 'orig'; } $fps = $input->getOption('fps'); if (empty($fps)) { $fps = '24'; } $bitRate = $input->getOption('bitrate'); if (empty($bitRate)) { $bitRate = '512'; } $vcodec = 'copy'; if ($this->ext == 'webm') { $vcodec = 'libvpx'; } // Find the files we want to treat, using Finder selectors $finder = new Finder(); $filter = function (\SplFileInfo $file, $ext, $orig) { $combinedExt = '.' . $orig . '.' . $ext; $combinedExtLength = strlen($combinedExt); $extLength = strlen('.' . $ext); if (substr($file->getRealPath(), -$combinedExtLength) == $combinedExt) { return false; } if (is_file(substr($file->getRealPath(), 0, -$extLength) . $combinedExt)) { $this->excluded[] = $file; return false; } }; $finder->sortByName()->files()->in($dir)->name('*.' . $this->ext)->filter($filter, $this->ext, $this->origExt); // Print the list of matching files we found if (count($finder) > 0) { $output->writeln('Videos found for conversion: '); foreach ($finder as $file) { $output->writeln($file->getRealpath()); } } else { if (count($this->excluded) > 0) { $output->writeln('The system has detected several videos already converted: '); foreach ($this->excluded as $file) { $output->writeln('- ' . $file->getRealPath()); } } $output->writeln('No video left to convert'); return; } $dialog = $this->getHelperSet()->get('dialog'); if (!$dialog->askConfirmation($output, '<question>All listed videos will be altered and a copy of the original will be taken with a .orig.webm extension. Are you sure you want to proceed? (y/N)</question>', false)) { return; } $fs = new Filesystem(); $time = time(); $counter = 0; $sizeNew = $sizeOrig = 0; foreach ($finder as $file) { $sizeOrig += $file->getSize(); $origName = $file->getRealPath(); $newName = substr($file->getRealPath(), 0, -4) . 'orig.webm'; $fs->rename($origName, $newName); $out = array(); $newNameCommand = preg_replace('/\\s/', '\\ ', $newName); $newNameCommand = preg_replace('/\\(/', '\\(', $newNameCommand); $newNameCommand = preg_replace('/\\)/', '\\)', $newNameCommand); $origNameCommand = preg_replace('/\\s/', '\\ ', $origName); $origNameCommand = preg_replace('/\\(/', '\\(', $origNameCommand); $origNameCommand = preg_replace('/\\)/', '\\)', $origNameCommand); $output->writeln('ffmpeg -i ' . $newNameCommand . ' -b ' . $bitRate . 'k -f ' . $this->ext . ' -vcodec ' . $vcodec . ' -acodec copy -r ' . $fps . ' ' . $origNameCommand); $exec = @system('ffmpeg -i ' . $newNameCommand . ' -b ' . $bitRate . 'k -f ' . $this->ext . ' -vcodec ' . $vcodec . ' -acodec copy -r ' . $fps . ' ' . $origNameCommand, $out); $sizeNew += filesize($origName); $counter++; } } $output->writeln(''); $output->writeln('Done converting all videos from ' . $dir); $output->writeln('Total videos converted: ' . $counter . ' videos in ' . (time() - $time) . ' seconds'); $output->writeln('Total size of old videos combined: ' . round($sizeOrig / (1024 * 1024)) . 'M'); $output->writeln('Total size of all new videos combined: ' . round($sizeNew / (1024 * 1024)) . 'M'); //$this->removeFiles($files, $output); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $dialog = $this->getHelperSet()->get('dialog'); $_configuration = $this->getHelper('configuration')->getConfiguration(); $file = $input->getArgument('file'); $connection = $this->getHelper('configuration')->getConnection(); if (is_file($file) && is_readable($file)) { $phar = new \PharData($file); if ($phar->hasMetadata()) { $langInfo = $phar->getMetadata(); $connection = $this->getHelper('configuration')->getConnection(); if ($connection) { $q = mysql_query("SELECT * FROM language WHERE dokeos_folder = '{$langInfo['dokeos_folder']}' "); $langInfoFromDB = mysql_fetch_array($q, MYSQL_ASSOC); $langFolderPath = $_configuration['root_sys'] . 'main/lang/' . $langInfoFromDB['dokeos_folder']; if ($langInfoFromDB && $langFolderPath) { //Overwrite lang files if (!$dialog->askConfirmation($output, '<question>The ' . $langInfo['original_name'] . ' language already exists in Chamilo. Did you want to overwrite the contents? (y/N)</question>', false)) { return; } if (is_writable($langFolderPath)) { $output->writeln("Trying to save files here: {$langFolderPath}"); $phar->extractTo($langFolderPath, null, true); // extract all files $output->writeln("Files were copied."); } else { $output->writeln("<error>Make sure that this folder {$langFolderPath} has writable permissions or execute the script with sudo </error>"); } } else { //Check if parent_id exists $parentId = ''; if (!empty($langInfo['parent_id'])) { $sql = "select selected_value from settings_current where variable = 'allow_use_sub_language'"; $result = mysql_query($sql); $subLanguageSetting = mysql_fetch_array($result, MYSQL_ASSOC); $subLanguageSetting = $subLanguageSetting['selected_value']; if ($subLanguageSetting == 'true') { $q = mysql_query("SELECT * FROM language WHERE id = '{$langInfo['parent_id']}' "); $parentLangInfoFromDB = mysql_fetch_array($q, MYSQL_ASSOC); if ($parentLangInfoFromDB) { $output->writeln("Setting parent language: " . $parentLangInfoFromDB['original_name']); $parentId = $langInfo['parent_id']; } else { $output->writeln("The lang parent_id = {$langInfo['parent_id']} does not exist in Chamilo. Try to import first the parent language."); exit; } } else { $output->writeln("<comment>Please turn ON the sublanguage feature in this portal</comment>"); exit; } } else { $output->writeln("Parent language was not provided"); } $q = mysql_query("INSERT INTO language (original_name, english_name, isocode, dokeos_folder, available, parent_id) VALUES (\n '" . $langInfo['original_name'] . "',\n '" . $langInfo['english_name'] . "',\n '" . $langInfo['isocode'] . "',\n '" . $langInfo['dokeos_folder'] . "',\n '1',\n '" . $parentId . "')"); if ($q) { $output->writeln("Language inserted in the DB"); $langFolderPath = $_configuration['root_sys'] . 'main/lang/' . $langInfo['dokeos_folder']; $phar->extractTo($langFolderPath, null, true); // extract all files $output->writeln("<comment>Files were copied here {$langFolderPath} </comment>"); } else { $output->writeln("An error ocurred while tring to create the language"); } } } } else { $output->writeln("<comment>The file is not a valid Chamilo language package<comment>"); } } else { $output->writeln("<comment>The file located in '{$file}' is not accessible<comment>"); } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $source = $input->getArgument('source'); $language = $input->getArgument('language'); $destination = $input->getArgument('dest'); $tgz = $input->getOption('tgz'); $allowNew = $input->getOption('new'); $_configuration = $this->getHelper('configuration')->getConfiguration(); $baseDir = $_configuration['root_sys']; if (substr($baseDir, -1, 1) != '/') { $baseDir .= '/'; } if (substr($source, -1, 1) != '/') { $source .= '/'; } if (substr($destination, -1, 1) != '/') { $destination .= '/'; } if (!is_dir($source)) { $output->writeln('The directory ' . $source . ' does not seem to exist. The source directory must exist and contain the language files, similar to e.g. /var/www/chamilo/main/lang/english'); exit; } // Generate a folder name for saving the *partial* files in the original language - use suffix "_partial $origLang = substr(substr($source, 0, -1), strrpos(substr($source, 0, -1), '/')) . '_partial'; if (!is_dir($destination)) { $output->writeln('The directory ' . $destination . ' does not seem to exist. The destination directory must exist in order for this script to write the results in a safe place'); exit; } if (!is_writeable($destination)) { $output->writeln('The destination directory must be writeable. ' . $destination . ' seems not to be writeable now.'); exit; } if (empty($language)) { $output->writeln('The destination language must be provided for this script to work. Received ' . $language . ', which could not be identified.'); exit; } $langDir = $baseDir . 'main/lang/'; $listDir = scandir($langDir); $langs = array(); foreach ($listDir as $lang) { if (substr($lang, 0, 1) == '.') { continue; } if (!is_dir($langDir . $lang)) { continue; } $langs[] = $lang; } $new = false; if (!in_array($language, $langs)) { if (!$allowNew) { $output->writeln('The destination language must be expressed as one of the directories available in your Chamilo installation. If you are exporting for the creation of a new language, use the --new option to ignore this warning'); exit; } else { $new = true; } } if (is_dir($destination . $language)) { if (!is_writeable($destination . $language)) { $output->writeln('Destination directory ' . $destination . $language . ' already exists but is not writeable. Please make sure whoever launches this script has privileges to write in there.'); exit; } $output->writeln('Destination directory ' . $destination . $language . ' already exists. We recommend using an empty directory. Files in this directory will be overwritten if necessary. Sorry.'); } elseif (!@mkdir($destination . $language)) { $output->writeln('For some reason, the directory creation returned an error for ' . $destination . $language); exit; } if (is_dir($destination . $origLang)) { if (!is_writeable($destination . $origLang)) { $output->writeln('Destination directory ' . $destination . $origLang . ' already exists but is not writeable. Please make sure whoever launches this script has privileges to write in there.'); exit; } $output->writeln('Destination directory ' . $destination . $origLang . ' already exists. We recommend using an empty directory. Files in this directory will be overwritten if necessary. Sorry.'); } elseif (!@mkdir($destination . $origLang)) { $output->writeln('For some reason, the directory creation returned an error for ' . $destination . $origLang); exit; } // Start working on those files! $listFiles = scandir($source); $countVars = 0; $countTranslatedVars = 0; $countWords = 0; $countTranslatedWords = 0; $fileString = '<?php' . "\n"; foreach ($listFiles as $file) { if (substr($file, -1, 1) == '.') { continue; } $destFileLines = $fileString; $origFileLines = $fileString; $partialSourceFile = $langDir . $language . '/' . $file; $output->writeln('Source File 2 = ' . $partialSourceFile); $sourceVars = $this->_getLangVars($source . $file); $source2Vars = array(); if (is_file($partialSourceFile)) { $source2Vars = $this->_getLangVars($partialSourceFile); } $source2Keys = array_keys($source2Vars); foreach ($sourceVars as $var => $val) { if (in_array($var, $source2Keys)) { $destFileLines .= '$' . $var . '=' . $source2Vars[$var] . "\n"; $origFileLines .= '$' . $var . '=' . $val . "\n"; $countTranslatedVars++; $countTranslatedWords += str_word_count($sourceVars[$var]); } else { $destFileLines .= '$' . $var . '="";' . "\n"; $origFileLines .= '$' . $var . '=' . $val . "\n"; } $countVars++; $countWords += str_word_count($sourceVars[$var]); } $output->writeln('Writing to file ' . $destination . $language . '/' . $file); $w = file_put_contents($destination . $language . '/' . $file, $destFileLines); $w = file_put_contents($destination . $origLang . '/' . $file, $origFileLines); } $output->writeln('Written translation files for packaging in ' . $destination . $language . '.'); $output->writeln('Found ' . $countVars . ' variables, of which ' . $countTranslatedVars . ' were already translated (and ' . ($countVars - $countTranslatedVars) . ' are missing).'); $output->writeln('In words, there are ' . $countWords . ' words in total, of which only ' . ($countWords - $countTranslatedWords) . ' still need translating.'); if ($tgz) { $output->writeln('Compressing as .tar.gz...'); chdir($destination); exec('tar zcf ' . $destination . $language . '.tar.gz ' . $language); $output->writeln('Written to ' . $destination . $language . '.tar.gz'); $output->writeln('Removing work directory ' . $destination . $language); exec('rm -rf ' . $destination . $language); } $output->writeln('Finished exporting language package.'); if (!$tgz) { $output->writeln('Please make sure you review your work directory for possible cleaning.'); } }