Permalink
Browse files

Small simplifications

  • Loading branch information...
flack committed Oct 8, 2017
1 parent 0bd878d commit 2e6d6a35e255766969def1e346c765c99a6b6b88
Showing with 147 additions and 275 deletions.
  1. +1 −2 lib/midcom/admin/folder/handler/move.php
  2. +1 −2 lib/midcom/admin/folder/management.php
  3. +7 −14 lib/midcom/baseclasses/core/dbobject.php
  4. +1 −2 lib/midcom/core/dbaobject.php
  5. +1 −1 lib/midcom/core/query.php
  6. +4 −5 lib/midcom/core/querybuilder.php
  7. +1 −2 lib/midcom/cron/loginservice.php
  8. +2 −4 lib/midcom/helper/_styleloader.php
  9. +3 −6 lib/midcom/helper/filesync/exporter/snippet.php
  10. +1 −2 lib/midcom/helper/filesync/exporter/structure.php
  11. +2 −4 lib/midcom/helper/filesync/exporter/style.php
  12. +2 −4 lib/midcom/helper/filesync/importer.php
  13. +1 −1 lib/midcom/helper/misc.php
  14. +1 −3 lib/midcom/helper/reflector/copy.php
  15. +1 −3 lib/midcom/services/at/cron/clean.php
  16. +2 −4 lib/midcom/services/auth/sessionmgr.php
  17. +1 −1 lib/midcom/services/cache/module.php
  18. +1 −2 lib/midcom/services/cache/module/content.php
  19. +1 −1 lib/midcom/services/dbclassloader.php
  20. +2 −3 lib/midcom/services/indexer/client.php
  21. +1 −2 lib/midcom/services/permalinks/main.php
  22. +3 −5 lib/midcom/services/rcs/backend/rcs.php
  23. +1 −4 lib/midcom/services/rcs/config.php
  24. +2 −4 lib/midgard/admin/asgard/exec/list_hidden_objects.php
  25. +1 −2 lib/midgard/admin/asgard/handler/object/permissions.php
  26. +2 −4 lib/midgard/admin/asgard/handler/undelete.php
  27. +1 −2 lib/midgard/admin/asgard/handler/welcome.php
  28. +5 −7 lib/midgard/admin/asgard/stylehelper.php
  29. +1 −2 lib/midgard/admin/user/handler/group/permissions.php
  30. +1 −2 lib/midgard/admin/user/style/midgard-admin-user-personlist-item.php
  31. +1 −2 lib/net/nehmer/blog/midcom/interfaces.php
  32. +1 −3 lib/net/nehmer/blog/navigation.php
  33. +1 −2 lib/net/nehmer/comments/cron/atom.php
  34. +1 −2 lib/net/nehmer/comments/exec/fix_authors.php
  35. +1 −3 lib/net/nehmer/static/handler/autoindex.php
  36. +1 −2 lib/net/nehmer/static/midcom/interfaces.php
  37. +1 −3 lib/net/nehmer/static/navigation.php
  38. +1 −4 lib/net/nemein/redirector/navigation.php
  39. +1 −2 lib/net/nemein/rss/cron/fetchfeeds.php
  40. +5 −11 lib/net/nemein/tag/handler.php
  41. +1 −2 lib/net/nemein/tag/midcom/interfaces.php
  42. +1 −2 lib/net/nemein/wiki/handler/feed.php
  43. +1 −2 lib/net/nemein/wiki/handler/latest.php
  44. +1 −2 lib/net/nemein/wiki/handler/orphan.php
  45. +1 −2 lib/net/nemein/wiki/parser.php
  46. +2 −4 lib/net/nemein/wiki/wikipage.php
  47. +1 −2 lib/org/openpsa/calendar/cron/reporthours.php
  48. +1 −2 lib/org/openpsa/contacts/cron/duplicates/clean.php
  49. +2 −4 lib/org/openpsa/contacts/duplicates/merge.php
  50. +1 −2 lib/org/openpsa/contacts/list.php
  51. +1 −2 lib/org/openpsa/directmarketing/campaign.php
  52. +1 −2 lib/org/openpsa/directmarketing/cleanup.php
  53. +1 −2 lib/org/openpsa/directmarketing/handler/logger.php
  54. +1 −2 lib/org/openpsa/directmarketing/handler/message/admin.php
  55. +3 −6 lib/org/openpsa/directmarketing/handler/subscriber.php
  56. +1 −2 lib/org/openpsa/directmarketing/midcom/interfaces.php
  57. +1 −2 lib/org/openpsa/directmarketing/navigation.php
  58. +3 −5 lib/org/openpsa/expenses/viewer.php
  59. +1 −2 lib/org/openpsa/helpers/list.php
  60. +1 −2 lib/org/openpsa/invoices/handler/rest/invoice.php
  61. +8 −12 lib/org/openpsa/invoices/invoice.php
  62. +4 −5 lib/org/openpsa/invoices/scheduler.php
  63. +4 −8 lib/org/openpsa/mypage/handler/weekreview.php
  64. +1 −2 lib/org/openpsa/products/handler/configuration.php
  65. +1 −2 lib/org/openpsa/products/handler/product/csv.php
  66. +3 −6 lib/org/openpsa/products/midcom/interfaces.php
  67. +1 −2 lib/org/openpsa/projects/exec/cache-invalidate.php
  68. +1 −2 lib/org/openpsa/projects/handler/frontpage.php
  69. +2 −4 lib/org/openpsa/projects/midcom/interfaces.php
  70. +1 −2 lib/org/openpsa/projects/task.php
  71. +1 −3 lib/org/openpsa/projects/task/resource.php
  72. +1 −2 lib/org/openpsa/projects/task/status.php
  73. +1 −3 lib/org/openpsa/projects/workflow.php
  74. +1 −2 lib/org/openpsa/relatedto/midcom/interfaces.php
  75. +5 −7 lib/org/openpsa/reports/handler/invoices/report.php
  76. +1 −2 lib/org/openpsa/sales/exec/cache-invalidate.php
  77. +1 −2 lib/org/openpsa/sales/exec/cleanup-at-entries.php
  78. +1 −2 lib/org/openpsa/sales/handler/view.php
  79. +1 −3 lib/org/openpsa/sales/midcom/interfaces.php
  80. +5 −6 lib/org/openpsa/sales/salesproject.php
  81. +4 −5 lib/org/openpsa/sales/salesproject/deliverable.php
  82. +3 −6 lib/org/openpsa/slideshow/handler/edit.php
  83. +2 −2 lib/org/openpsa/widgets/tree.php
@@ -108,9 +108,8 @@ public function show_tree(midcom_db_topic $folder = null, $tree_disabled = false
$qb = midcom_db_topic::new_query_builder();
$qb->add_constraint('up', '=', $folder->id);
$qb->add_constraint('component', '<>', '');
$children = $qb->execute();
foreach ($children as $child) {
foreach ($qb->execute() as $child) {
$this->show_tree($child, $tree_disabled);
}
echo "</li>\n";
@@ -125,9 +125,8 @@ public static function list_styles($up = 0, $prefix = '/', $spacer = '')
$qb = midcom_db_style::new_query_builder();
$qb->add_constraint('up', '=', $up);
$styles = $qb->execute();
foreach ($styles as $style) {
foreach ($qb->execute() as $style) {
$style_string = "{$prefix}{$style->name}";
// Hide common unwanted material with heuristics
@@ -497,8 +497,7 @@ public static function undelete_parameters($guid)
$qb->include_deleted();
$qb->add_constraint('parentguid', '=', $guid);
$qb->add_constraint('metadata.deleted', '=', true);
$params = $qb->execute();
foreach ($params as $param) {
foreach ($qb->execute() as $param) {
if ($param->undelete($param->guid)) {
$undeleted_size += $param->metadata->size;
}
@@ -522,8 +521,7 @@ public static function undelete_attachments($guid)
$qb->include_deleted();
$qb->add_constraint('parentguid', '=', $guid);
$qb->add_constraint('metadata.deleted', '=', true);
$atts = $qb->execute();
foreach ($atts as $att) {
foreach ($qb->execute() as $att) {
if ($att->undelete($att->guid)) {
midcom::get()->uimessages->add(midcom::get()->i18n->get_string('midgard.admin.asgard', 'midgard.admin.asgard'), sprintf(midcom::get()->i18n->get_string('attachment %s undeleted', 'midgard.admin.asgard'), $att->name, midcom_connection::get_error_string()));
$undeleted_size += $att->metadata->size;
@@ -599,8 +597,7 @@ public static function purge_parameters($guid)
$qb = new midgard_query_builder('midgard_parameter');
$qb->include_deleted();
$qb->add_constraint('parentguid', '=', $guid);
$params = $qb->execute();
foreach ($params as $param) {
foreach ($qb->execute() as $param) {
if ($param->purge()) {
$purged_size += $param->metadata->size;
} else {
@@ -628,8 +625,7 @@ public static function purge_attachments($guid)
$qb = new midgard_query_builder('midgard_attachment');
$qb->include_deleted();
$qb->add_constraint('parentguid', '=', $guid);
$atts = $qb->execute();
foreach ($atts as $att) {
foreach ($qb->execute() as $att) {
if ($att->purge()) {
$purged_size += $att->metadata->size;
self::purge_parameters($att->guid);
@@ -777,9 +773,8 @@ private static function _delete_privileges(midcom_core_dbaobject $object)
{
$qb = new midgard_query_builder('midcom_core_privilege_db');
$qb->add_constraint('objectguid', '=', $object->guid);
$result = $qb->execute();
foreach ($result as $dbpriv) {
foreach ($qb->execute() as $dbpriv) {
if (!$dbpriv->purge()) {
return false;
}
@@ -905,9 +900,8 @@ private static function _list_parameters_domain(midcom_core_dbaobject $object, $
$mc->add_value_property('value');
$mc->add_constraint('domain', '=', $domain);
$mc->execute();
$parameters = $mc->list_keys();
foreach ($parameters as $name => $values) {
foreach ($mc->list_keys() as $name => $values) {
self::$parameter_cache[$object->guid][$domain][$name] = $mc->get_subkey($name, 'value');
}
@@ -936,9 +930,8 @@ private static function _list_parameters_all(midcom_core_dbaobject $object)
$mc->add_value_property('name');
$mc->add_value_property('value');
$mc->execute();
$parameters = $mc->list_keys();
foreach ($parameters as $guid => $values) {
foreach ($mc->list_keys() as $guid => $values) {
$name = $mc->get_subkey($guid, 'name');
$domain = $mc->get_subkey($guid, 'domain');
@@ -562,8 +562,7 @@ private function _delete_dependents()
foreach ($this->autodelete_dependents as $classname => $link_property) {
$qb = midcom::get()->dbfactory->new_query_builder($classname);
$qb->add_constraint($link_property, '=', $this->id);
$results = $qb->execute();
foreach ($results as $result) {
foreach ($qb->execute() as $result) {
if (!$result->delete()) {
debug_add('Could not delete dependent ' . $classname . ' #' . $result->id . ', aborting', MIDCOM_LOG_WARN);
return false;
@@ -103,7 +103,7 @@ protected function _convert_class($classname)
static $_class_mapping_cache = [];
$this->_real_class = $classname;
if (empty($_class_mapping_cache[$classname])) {
if (!array_key_exists($classname, $_class_mapping_cache)) {
if (!is_subclass_of($classname, 'midcom_core_dbaobject')) {
throw new midcom_error(
"Cannot create a midcom_core_query instance for the type {$classname}: Does not seem to be a DBA class name."
@@ -51,13 +51,12 @@ public function __construct($classname)
*/
private function _execute_and_check_privileges()
{
$result = $this->_query->execute();
$newresult = [];
$result = [];
foreach ($result as $object) {
foreach ($this->_query->execute() as $object) {
$classname = $this->_real_class;
try {
$newresult[] = new $classname($object);
$result[] = new $classname($object);
} catch (midcom_error $e) {
if ($e->getCode() == MIDCOM_ERRFORBIDDEN) {
$this->denied++;
@@ -66,7 +65,7 @@ private function _execute_and_check_privileges()
}
}
return $newresult;
return $result;
}
/**
@@ -17,8 +17,7 @@ public function _on_execute()
$qb = new midgard_query_builder('midcom_core_login_session_db');
$qb->add_constraint('timestamp', '<', time() - midcom::get()->config->get('auth_login_session_timeout'));
$qb->set_limit(500);
$result = $qb->execute();
foreach ($result as $tmp) {
foreach ($qb->execute() as $tmp) {
if (!$tmp->purge()) {
$msg = "Failed to purge login session {$tmp->id}, last Midgard error was: " . midcom_connection::get_error_string();
$this->print_error($msg, $tmp);
@@ -235,9 +235,8 @@ private function _get_element_in_styletree($id, $name)
$element_mc->add_value_property('value');
$element_mc->add_constraint('name', '=', $name);
$element_mc->execute();
$elements = $element_mc->list_keys();
foreach ($elements as $element_guid => $value) {
foreach ($element_mc->list_keys() as $element_guid => $value) {
$value = $element_mc->get_subkey($element_guid, 'value');
midcom::get()->cache->content->register($element_guid);
$cached[$cache_key] = $value;
@@ -249,9 +248,8 @@ private function _get_element_in_styletree($id, $name)
$style_mc->set_key_property('guid');
$style_mc->add_value_property('up');
$style_mc->execute();
$styles = $style_mc->list_keys();
foreach ($styles as $style_guid => $value) {
foreach ($style_mc->list_keys() as $style_guid => $value) {
midcom::get()->cache->content->register($style_guid);
if ($up = $style_mc->get_subkey($style_guid, 'up')) {
@@ -25,8 +25,7 @@ private function read_snippetdir($snippetdir, $path)
$snippet_qb = midcom_db_snippet::new_query_builder();
$snippet_qb->add_constraint('snippetdir', '=', $snippetdir->id);
$snippets = $snippet_qb->execute();
foreach ($snippets as $snippet) {
foreach ($snippet_qb->execute() as $snippet) {
file_put_contents("{$snippetdir_path}/{$snippet->name}.php", $snippet->code);
$filenames[] = "{$snippet->name}.php";
@@ -38,8 +37,7 @@ private function read_snippetdir($snippetdir, $path)
$dir_qb = midcom_db_snippetdir::new_query_builder();
$dir_qb->add_constraint('up', '=', $snippetdir->id);
$dirs = $dir_qb->execute();
foreach ($dirs as $dir) {
foreach ($dir_qb->execute() as $dir) {
$this->read_snippetdir($dir, "{$snippetdir_path}/");
$foldernames[] = $dir->name;
}
@@ -68,8 +66,7 @@ public function export()
{
$qb = midcom_db_snippetdir::new_query_builder();
$qb->add_constraint('up', '=', 0);
$rootdirs = $qb->execute();
foreach ($rootdirs as $rootdir) {
foreach ($qb->execute() as $rootdir) {
if ($rootdir->can_do('midgard:update')) {
$this->read_snippetdir($rootdir, $this->root_dir);
}
@@ -37,8 +37,7 @@ private function read_node(midcom_db_topic $node)
$node_array['nodes'] = [];
$qb = midcom_db_topic::new_query_builder();
$qb->add_constraint('up', '=', $node->id);
$children = $qb->execute();
foreach ($children as $child) {
foreach ($qb->execute() as $child) {
$node_array['nodes'][$child->name] = $this->read_node($child);
}
@@ -25,17 +25,15 @@ public function read_style($style, $path)
$element_qb = midcom_db_element::new_query_builder();
$element_qb->add_constraint('style', '=', $style->id);
$elements = $element_qb->execute();
foreach ($elements as $element) {
foreach ($element_qb->execute() as $element) {
file_put_contents("{$style_path}/{$element->name}.php", $element->value);
$filenames[] = "{$element->name}.php";
}
$style_qb = midcom_db_style::new_query_builder();
$style_qb->add_constraint('up', '=', $style->id);
$styles = $style_qb->execute();
foreach ($styles as $style) {
foreach ($style_qb->execute() as $style) {
$this->read_style($style, "{$style_path}/");
$foldernames[] = $style->name;
}
@@ -115,8 +115,7 @@ public function delete_missing_folders(array $foldernames, $parent_id)
$qb = $this->get_node_qb($parent_id);
$qb->add_constraint('name', 'NOT IN', $foldernames);
$folders = $qb->execute();
foreach ($folders as $folder) {
foreach ($qb->execute() as $folder) {
$folder->delete();
}
}
@@ -126,8 +125,7 @@ public function delete_missing_files(array $filenames, $parent_id)
$qb = $this->get_leaf_qb($parent_id);
$qb->add_constraint('name', 'NOT IN', $filenames);
$files = $qb->execute();
foreach ($files as $file) {
foreach ($qb->execute() as $file) {
$file->delete();
}
}
@@ -272,7 +272,7 @@ public static function filesize_to_string($size)
* @param string $data The data to fix.
* @return string $data with serializations fixed.
*/
public static function fix_serialization($data = null)
public static function fix_serialization($data)
{
//Skip on empty data
if (empty($data)) {
@@ -467,9 +467,7 @@ public function copy_privileges($source, $target)
$qb = midcom_core_privilege_db::new_query_builder();
$qb->add_constraint('objectguid', '=', $source->guid);
$results = $qb->execute();
foreach ($results as $privilege) {
foreach ($qb->execute() as $privilege) {
$new = new midcom_core_privilege_db();
$new->objectguid = $target->guid;
@@ -25,9 +25,7 @@ public function _on_execute()
$qb->add_constraint('status', '>=', midcom_services_at_entry_dba::RUNNING);
midcom::get()->auth->request_sudo('midcom.services.at');
$qbret = $qb->execute();
foreach ($qbret as $entry) {
foreach ($qb->execute() as $entry) {
debug_add("Deleting dangling entry #{$entry->id}\n", MIDCOM_LOG_INFO);
debug_print_r("Entry #{$entry->id} dump: ", $entry);
$entry->delete();
@@ -343,9 +343,8 @@ function _update_user_username($user, $new)
}
$qb = new midgard_query_builder('midcom_core_login_session_db');
$qb->add_constraint('userid', '=', $user->id);
$result = $qb->execute();
foreach ($result as $session) {
foreach ($qb->execute() as $session) {
$session->username = $new;
$session->update();
}
@@ -423,8 +422,7 @@ function get_online_users()
$mc->execute();
$result = [];
$query_result = array_keys($mc->list_keys());
foreach ($query_result as $userid) {
foreach (array_keys($mc->list_keys()) as $userid) {
if ( ($user = $this->auth->get_user($userid))
&& $user->is_online()) {
$result[$user->guid] = $user;
@@ -103,7 +103,7 @@ private function prepare_backend(array $config, $name)
$memcache_operational = false;
switch ($config['driver']) {
case 'apc':
$backend = new Cache\ApcCache();
$backend = new Cache\ApcuCache();
break;
case 'memcached':
$host = !empty($config['host']) ? $config['host'] : 'localhost';
@@ -851,8 +851,7 @@ private function complete_sent_headers(Response $response)
if ($response->getExpires()) {
$this->register_sent_header('Expires', $response->headers->get('Expires'));
}
if ( is_array($this->_force_headers)
&& !empty($this->_force_headers)) {
if (is_array($this->_force_headers)) {
foreach ($this->_force_headers as $header => $value) {
$response->headers->set($header, $value);
$this->register_sent_header($header, $value);
@@ -169,7 +169,7 @@ public function get_component_for_class($classname)
];
foreach ($class_parts as $part) {
if (empty($component)) {
if ($component == '') {
$component = $part;
} else {
$component .= ".{$part}";
@@ -85,11 +85,10 @@ public function add_query($name, midcom_core_querybuilder $qb, $schemadb)
public function reindex()
{
foreach ($this->_queries as $name => $data) {
$qb = $data[0];
foreach ($this->_queries as $name => list($qb, $schemadb)) {
$results = $qb->execute();
if (!empty($results)) {
$documents = $this->process_results($name, $results, $data[1]);
$documents = $this->process_results($name, $results, $schemadb);
if (!empty($documents)) {
$this->_indexer->index($documents);
}
@@ -124,8 +124,7 @@ public function resolve_permalink($guid)
$topic_qb = midcom_db_topic::new_query_builder();
$topic_qb->add_constraint('name', '<>', '');
$topic_qb->add_constraint('up', 'INTREE', midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ROOTTOPICID));
$topics = $topic_qb->execute();
foreach ($topics as $topic) {
foreach ($topic_qb->execute() as $topic) {
if ($result = $this->_resolve_permalink_in_topic($topic, $object)) {
return $result;
}
@@ -348,11 +348,9 @@ private function rcs_writefile($guid, $data)
*/
private function rcs_readfile($guid)
{
if (!empty($guid)) {
$filename = $this->_generate_rcs_filename($guid);
if (file_exists($filename)) {
return file_get_contents($filename);
}
$filename = $this->_generate_rcs_filename($guid);
if (file_exists($filename)) {
return file_get_contents($filename);
}
return '';
}
@@ -48,10 +48,7 @@ public function get_handler($object)
public function get_rcs_root()
{
if (empty($this->config['midcom_services_rcs_root'])) {
$basedir = "/var/lib/midgard";
if (midgard_connection::get_instance()) {
$basedir = dirname(midgard_connection::get_instance()->config->sharedir);
}
$basedir = dirname(midgard_connection::get_instance()->config->sharedir);
$this->config['midcom_services_rcs_root'] = $basedir . '/rcs';
}
Oops, something went wrong.

0 comments on commit 2e6d6a3

Please sign in to comment.