function main_appcentral($eventData) { global $gLocale, $gXmlDefinition, $gPageTitle, $gStatus, $gToolbars; $repsQuery = \Innomatic\Core\InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer')->getDataAccess()->execute('SELECT applications_repositories.id AS id, applications_repositories.accountid AS accountid, webservices_accounts.name AS name FROM applications_repositories,webservices_accounts WHERE applications_repositories.accountid=webservices_accounts.id ORDER BY name'); $newRepXml = ''; $accsQuery = \Innomatic\Core\InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer')->getDataAccess()->execute('SELECT id, name FROM webservices_accounts WHERE webservices_accounts.id NOT IN (SELECT accountid FROM applications_repositories) ORDER BY name'); $accounts = array(); while (!$accsQuery->eof) { $accounts[$accsQuery->getFields('id')] = $accsQuery->getFields('name'); $accsQuery->moveNext(); } if ($accsQuery->getNumberRows()) { $newRepXml = ' <form><name>newrepository</name> <args> <method>post</method> <action type="encoded">' . urlencode(\Innomatic\Wui\Dispatch\WuiEventsCall::buildEventsCallString('', array(array('view', 'appcentral', ''), array('action', 'newrepository', '')))) . '</action> </args> <children> <grid><name>new</name> <children> <label row="0" col="0"><name>name</name> <args> <label type="encoded">' . urlencode($gLocale->getStr('account.label')) . '</label> </args> </label> <combobox row="0" col="1"><name>accountid</name> <args> <disp>action</disp> <elements type="array">' . WuiXml::encode($accounts) . '</elements> </args> </combobox> <button row="0" col="2"><name>apply</name> <args> <themeimage>mathadd</themeimage> <formsubmit>newrepository</formsubmit> <horiz>true</horiz> <frame>false</frame> <label type="encoded">' . urlencode($gLocale->getStr('new_repository.submit')) . '</label> <action type="encoded">' . urlencode(\Innomatic\Wui\Dispatch\WuiEventsCall::buildEventsCallString('', array(array('view', 'appcentral', ''), array('action', 'newrepository', '')))) . '</action> </args> </button> </children> </grid> </children> </form>'; } // Refresh repositories and applications list if requested if (isset($eventData['refresh'])) { $helper = new \Innomatic\Application\AppCentralHelper(); $helper->updateApplicationsList(); } if ($repsQuery->getNumberRows()) { $tabs = array(); while (!$repsQuery->eof) { $tabs[]['label'] = $repsQuery->getFields('name'); $repsQuery->moveNext(); } $headers[0]['label'] = $gLocale->getStr('repository_name.header'); $gXmlDefinition = '<vertgroup><name>reps</name> <children> <tab><name>repositories</name> <args> <tabs type="array">' . WuiXml::encode($tabs) . '</tabs> <tabactionfunction>reps_tab_action_builder</tabactionfunction> <activetab>' . (isset($eventData['activetab']) ? $eventData['activetab'] : '') . '</activetab> </args> <children>'; $repsQuery->MoveFirst(); while (!$repsQuery->eof) { $acRemote = new \Innomatic\Application\AppCentralRemoteServer($repsQuery->getFields('id')); $availReps = $acRemote->listAvailableRepositories(); $gXmlDefinition .= '<vertgroup><name>tab</name><children> <table><name>reps</name> <args> <headers type="array">' . WuiXml::encode($headers) . '</headers> </args> <children>'; $row = 0; if (is_array($availReps)) { while (list($id, $data) = each($availReps)) { $gXmlDefinition .= '<label row="' . $row . '" col="0"><name>rep</name> <args> <label type="encoded">' . urlencode('<strong>' . $data['name'] . '</strong><br>' . $data['description']) . '</label> </args> </label> <horizgroup row="' . $row . '" col="1"><name>tb</name> <children> <button> <args> <label>' . WuiXml::cdata($gLocale->getStr('repository_applications.button')) . '</label> <themeimage>listdetailed</themeimage> <horiz>true</horiz> <action>' . WuiXml::cdata(\Innomatic\Wui\Dispatch\WuiEventsCall::buildEventsCallString('', array(array('view', 'repositoryapplications', array('id' => $repsQuery->getFields('id'), 'repid' => $id))))) . '</action> </args> </button> </children> </horizgroup>'; $row++; } } $gXmlDefinition .= ' </children> </table> <horizbar><name>hb</name></horizbar> <button><name>remove</name> <args> <themeimage>trash</themeimage> <horiz>true</horiz> <frame>false</frame> <action type="encoded">' . urlencode(\Innomatic\Wui\Dispatch\WuiEventsCall::buildEventsCallString('', array(array('view', 'appcentral', ''), array('action', 'removerepository', array('id' => $repsQuery->getFields('id')))))) . '</action> <label type="encoded">' . urlencode($gLocale->getStr('remove_account.button')) . '</label> <needconfirm>true</needconfirm> <confirmmessage type="encoded">' . urlencode($gLocale->getStr('remove_account.confirm')) . '</confirmmessage> </args> </button> </children></vertgroup>'; $repsQuery->moveNext(); } $gXmlDefinition .= ' </children> </tab>'; if (strlen($newRepXml)) { $gXmlDefinition .= '<horizbar><name>hb</name></horizbar>' . $newRepXml; } $gXmlDefinition .= ' </children> </vertgroup>'; $gToolbars['reptools'] = array('refresh' => array('label' => $gLocale->getStr('refresh.button'), 'themeimage' => 'cycle', 'horiz' => 'true', 'action' => \Innomatic\Wui\Dispatch\WuiEventsCall::buildEventsCallString('', array(array('view', 'appcentral', array('refresh' => '1')))))); } else { if (strlen($newRepXml)) { $gXmlDefinition .= $newRepXml; } else { $gXmlDefinition .= '<vertgroup><name>new</name> <children> <button><name>addaccount</name> <args> <themeimage>globe2</themeimage> <horiz>true</horiz> <frame>false</frame> <action type="encoded">' . urlencode('http://www.appcentral.it/') . '</action> <label type="encoded">' . urlencode($gLocale->getStr('new_appcentral_account.button')) . '</label> </args> </button> <button><name>addaccount2</name> <args> <themeimage>mathadd</themeimage> <horiz>true</horiz> <frame>false</frame> <action type="encoded">' . urlencode(\Innomatic\Wui\Dispatch\WuiEventsCall::buildEventsCallString('webservices', array(array('view', 'newaccount', '')))) . '</action> <label type="encoded">' . urlencode($gLocale->getStr('new_webservices_account.button')) . '</label> </args> </button> </children> </vertgroup>'; } if (!strlen($gStatus)) { $gStatus = $gLocale->getStr('no_repositories.status'); } } $gPageTitle .= ' - ' . $gLocale->getStr('repositories.title'); }
} break; case 'undeploy': $appid = \Innomatic\Application\Application::getAppIdFromName($argv[2]); $app = new \Innomatic\Application\Application(InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer')->getDataAccess(), $appid); if ($app->uninstall()) { print "Application {$argv['2']} undeployed\n"; $script->cleanExit(); } else { print "Application {$argv['2']} not undeployed\n"; $script->cleanExit(1); } break; case 'update': $appCentral = new \Innomatic\Application\AppCentralHelper(); $appCentral->updateApplicationsList(function ($serverId, $serverName, $repoId, $repoData) { print 'Server ' . $serverName . ' - Repository ' . $repoData['name'] . '... '; }, function ($result) { print 'done' . PHP_EOL; }); print "Applications list updated\n"; $script->cleanExit(); break; default: print 'Usage: php innomatic/core/scripts/application.php command' . "\n"; print 'Type application.php -h for a list of supported commands' . "\n"; } } catch (\Exception $e) { echo $e; } $script->cleanExit();