public function header($message){ if($this->realtime){ CLI::PrintHeader($message); } $this->log[] = '** ' . $message; }
CLI::PrintHeader('Assembling GPG Keys for ' . $b['name'] . ' ' . $version); foreach($xml->getElements('//key') as $el){ $id = $el->getAttribute('id'); CLI::PrintActionStart('Exporting key ' . $id); exec('gpg -a --export ' . $id . ' > "' . $destdir . '/' . $id . '.gpg"'); exec('gpg --homedir "' . $destdir . '/' . $desttgz . '/gnupg" --no-permission-warning --import "' . $destdir . '/' . $id . '.gpg"', $output, $result); unlink($destdir . '/' . $id . '.gpg'); CLI::PrintActionStatus('ok'); } } // Write out the changelog for the bundle. file_put_contents($destdir . '/' . $desttgz . '/packages.html', $changelog); CLI::PrintHeader('Finalizing Bundling for ' . $b['name'] . ' ' . $version); // create the tarballs! CLI::PrintActionStart("Creating tarball"); //exec('tar -czf "' . $destdir . '/' . $desttgz . '.tgz" -C "' . $destdir . '" --exclude-vcs --exclude=*~ --exclude=._* ' . $desttgz); exec('tar -czf "' . $destdir . '/' . $desttgz . '.tgz" -C "' . $destdir . '/' . $desttgz . '" --exclude-vcs --exclude=*~ --exclude=._* .'); CLI::PrintActionStatus('ok'); CLI::PrintActionStart("Creating zip"); //exec('cd "' . $destdir . '/"; zip -rq "' . $desttgz . '.zip" "' . $desttgz . '"; cd -'); exec('cd "' . $destdir . '/' . $desttgz . '/"; zip -rq "../' . $desttgz . '.zip" .; cd -'); CLI::PrintActionStatus('ok'); CLI::PrintActionStart("Creating hashes"); exec('md5sum "' . $destdir . '/' . $desttgz . '.tgz" > "' . $destdir . '/' . $desttgz . '.tgz.md5"'); exec('md5sum "' . $destdir . '/' . $desttgz . '.zip" > "' . $destdir . '/' . $desttgz . '.zip.md5"');
public function email_test(){ // Admin-only page. if(!\Core\user()->checkAccess('g:admin')){ return View::ERROR_ACCESSDENIED; } $request = $this->getPageRequest(); $view = $this->getView(); if(!$request->isPost()){ return View::ERROR_BADREQUEST; } if(!$request->getPost('email')){ return View::ERROR_BADREQUEST; } $view->mode = View::MODE_NOOUTPUT; $view->contenttype = View::CTYPE_HTML; $view->render(); $dest = $request->getPost('email'); $method = ConfigHandler::Get('/core/email/mailer'); $smtpHost = ConfigHandler::Get('/core/email/smtp_host'); $smtpUser = ConfigHandler::Get('/core/email/smtp_user'); $smtpPass = ConfigHandler::Get('/core/email/smtp_password'); $smtpPort = ConfigHandler::Get('/core/email/smtp_port'); $smtpSec = ConfigHandler::Get('/core/email/smtp_security'); $sendmailPath = ConfigHandler::Get('/core/email/sendmail_path'); $emailDebug = []; $emailDebug[] = 'Sending Method: ' . $method; switch($method){ case 'smtp': $emailDebug[] = 'SMTP Host: ' . $smtpHost . ($smtpPort ? ':' . $smtpPort : ''); $emailDebug[] = 'SMTP User/Pass: '******'//' . ($smtpPass ? '*** saved ***' : 'NO PASS') : 'Anonymous'); $emailDebug[] = 'SMTP Security: ' . $smtpSec; break; case 'sendmail': $emailDebug[] = 'Sendmail Path: ' . $sendmailPath; break; } CLI::PrintHeader('Sending test email to ' . $dest); CLI::PrintActionStart('Initializing Email System'); try{ $email = new Email(); $email->addAddress($dest); $email->setSubject('Test Email'); $email->templatename = 'emails/admin/test_email.tpl'; $email->assign('debugs', $emailDebug); $email->getMailer()->SMTPDebug = 2; CLI::PrintActionStatus(true); } catch(Exception $e){ CLI::PrintActionStatus(false); CLI::PrintError($e->getMessage()); CLI::PrintLine($e->getTrace()); return; } CLI::PrintActionStart('Sending Email via ' . $method); try{ $email->send(); CLI::PrintActionStatus(true); } catch(Exception $e){ CLI::PrintActionStatus(false); CLI::PrintError($e->getMessage()); CLI::PrintLine(explode("\n", $e->getTraceAsString())); } CLI::PrintHeader('Sent Headers:'); CLI::PrintLine(explode("\n", $email->getMailer()->CreateHeader())); CLI::PrintHeader('Sent Body:'); CLI::PrintLine(explode("\n", $email->getMailer()->CreateBody())); }
// All Models MUST reside in the global namespace in order to be valid. continue; } $ref = new ReflectionClass($class); if(!$ref->getProperty('HasSearch')->getValue()){ // This model doesn't have the searchable flag, skip it. continue; } CLI::PrintActionStart("Syncing searchable model $class"); $fac = new ModelFactory($class); foreach($fac->get() as $m){ /** @var Model $m */ $m->set('search_index_pri', '!'); $m->save(); } CLI::PrintActionStatus('ok'); $changes[] = "Synced searchable model " . $class; } } // Flush the system cache, just in case \Core\Cache::Flush(); \Core\Templates\Backends\Smarty::FlushCache(); CLI::PrintHeader('DONE!'); foreach($changes as $line){ CLI::PrintLine($line); }
} elseif(!$linesadded){ CLI::PrintLine('No new GIT commits found.'); } else{ CLI::PrintLine('Added ' . $linesadded . ($linesadded != 1 ? ' lines' : ' line') . ' to the changelog successfully!'); print $thischange->fetchFormatted() . NL . NL; } // Cleanup unset($thischange, $versioncheck, $previouschange, $previousdate, $changes, $linecount, $linesadded, $line); } break; case 'viewchange': // Just print the current CHANGELOG section, easy now that everything is compartmentalized. CLI::PrintHeader('CHANGELOG for ' . $packager->getLabel() . ' ' . $packager->getVersion()); CLI::PrintLine($packager->getChangelogSection()->fetchFormatted()); break; case 'save': CLI::PrintActionStart('Saving ' . $packager->getLabel()); $packager->save(); CLI::PrintActionStatus('ok'); $saved = true; $saveopts = [ 'package-sign-commit' => 'Create signed package and GIT commit any changes', 'package-sign' => 'Create signed package', 'package' => 'Create unsigned package', 'commit' => 'GIT commit any changes', 'menu' => 'Do nothing else, back to menu', 'quit' => 'Do nothing else and exit script',
/** * Upgrade this component to the newer version, if possible. * * Returns false if nothing changed, else will return an array containing all changes. * * @param boolean $next Set to true to run the "next" upgrades as well as any current. * @param boolean $verbose Set to true to enable real-time output * * @return boolean | array * @throws InstallerException */ public function upgrade($next = false, $verbose = false) { if (!$this->isInstalled()){ if($verbose) CLI::PrintDebug('Skipping ' . $this->getName() . ' as it is marked as uninstalled.'); return false; } if($verbose) CLI::PrintHeader('Beginning upgrade for ' . $this->getName()); $changes = array(); // I can now do everything else. $otherchanges = $this->_performInstall(); if ($otherchanges !== false) $changes = array_merge($changes, $otherchanges); $canBeUpgraded = true; while ($canBeUpgraded) { // Set as false to begin with, (will be set back to true if an upgrade is ran). $canBeUpgraded = false; foreach ($this->_xmlloader->getRootDOM()->getElementsByTagName('upgrade') as $u) { /** @var $u DOMElement */ $from = $u->getAttribute('from'); $to = $u->getAttribute('to') ? $u->getAttribute('to') : 'next'; // look for a valid upgrade path. if (($this->_versionDB == $from) || ($next && $from == 'next')) { // w00t, found one... $canBeUpgraded = true; if($verbose){ CLI::PrintLine('Processing upgrade from ' . $from . ' to ' . $to); } // This gets a bit tricky, I need to get all the valid upgrade elements in the order that they // are defined in the component.xml. $children = $u->childNodes; // The various upgrade tasks that can happen foreach($children as $child){ /** @var $child DOMElement */ switch($child->nodeName){ case 'dataset': $datachanges = $this->_parseDatasetNode($child, $verbose); if($datachanges !== false) $changes = array_merge($changes, $datachanges); break; case 'phpfileinclude': // I need to do this in a method so that include file doesn't mess with my local variables! $this->_includeFileForUpgrade(ROOT_PDIR . trim($child->nodeValue), $verbose); $changes[] = 'Included custom php file ' . basename($child->nodeValue); break; case 'php': $file = $child->getAttribute('file'); if($file){ // I need to do this in a method so that include file doesn't mess with my local variables! $this->_includeFileForUpgrade($this->getBaseDir() . $file, $verbose); $changes[] = 'Included custom php file ' . $file; } else{ $changes[] = 'Ignoring invalid <php> directive, no file attribute provided!'; } break; case 'sql': $file = $child->getAttribute('file'); if($file){ if($verbose){ CLI::PrintActionStart('Executing SQL statements from ' . $file); } $contents = file_get_contents($this->getBaseDir() . $file); $execs = 0; $parser = new SQL_Parser_Dataset($contents, SQL_Parser::DIALECT_MYSQL); $datasets = $parser->parse(); foreach($datasets as $ds){ $ds->execute(); $execs++; } if($verbose){ CLI::PrintActionStatus(true); } $changes[] = 'Executed custom sql file ' . $file . ' and ran ' . $execs . ($execs == 1 ? ' query' : ' queries'); } else{ $changes[] = 'Ignoring invalid <sql> directive, no file attribute provided!'; } break; case '#text': // This can be ignored without triggering any notice. break; default: $changes[] = 'Ignoring unsupported upgrade directive: [' . $child->nodeName . ']'; } } // Record this change. $changes[] = 'Upgraded from [' . $this->_versionDB . '] to [' . $u->getAttribute('to') . ']'; SystemLogModel::LogInfoEvent('/updater/component/upgrade', 'Component ' . $this->getName() . ' upgraded successfully from ' . $this->_versionDB . ' to ' . $u->getAttribute('to') . '!', implode("\n", $changes)); if($to == 'next'){ $canBeUpgraded = false; } else{ $this->_versionDB = $to; $c = new ComponentModel($this->_name); $c->set('version', $this->_versionDB); $c->save(); } } } } if(sizeof($changes) == 0 && $verbose){ CLI::PrintLine('No changes performed.'); } return (sizeof($changes)) ? $changes : false; }