| 61 | | return $stat; |
|---|
| | 62 | return midcom_helper_replicator_serialize_check_bug244($stat, $object); |
|---|
| | 63 | } |
|---|
| | 64 | |
|---|
| | 65 | /** |
|---|
| | 66 | * Checks if serialization would trigger bug #244, if so returns failure |
|---|
| | 67 | * and raises UI message. |
|---|
| | 68 | * |
|---|
| | 69 | * @param string $serialized reference to serialized object |
|---|
| | 70 | * @return string $serialized or false if triggers bug #244 |
|---|
| | 71 | */ |
|---|
| | 72 | function midcom_helper_replicator_serialize_check_bug244(&$serialized, &$object) |
|---|
| | 73 | { |
|---|
| | 74 | //debug_push_class('function', __FUNCTION__); |
|---|
| | 75 | if (!preg_match_all('%<.+?lang=.+?>%', $serialized, $matches)) |
|---|
| | 76 | { |
|---|
| | 77 | // not ML or no extra languages present. |
|---|
| | 78 | /* |
|---|
| | 79 | debug_add('no lang matches'); |
|---|
| | 80 | debug_pop(); |
|---|
| | 81 | */ |
|---|
| | 82 | return $serialized; |
|---|
| | 83 | } |
|---|
| | 84 | //debug_print_r('$matches: ', $matches); |
|---|
| | 85 | $langs = count($matches[0]); |
|---|
| | 86 | unset($matches); |
|---|
| | 87 | if ($langs <= 1) |
|---|
| | 88 | { |
|---|
| | 89 | // master + 1 does not trigger bug #244 |
|---|
| | 90 | /* |
|---|
| | 91 | debug_add("\$langs <= 1, does not trigger bug #244"); |
|---|
| | 92 | debug_pop(); |
|---|
| | 93 | */ |
|---|
| | 94 | unset($langs); |
|---|
| | 95 | return $serialized; |
|---|
| | 96 | } |
|---|
| | 97 | if ($langs % 2 == 0) |
|---|
| | 98 | { |
|---|
| | 99 | //debug_add("\$langs={$langs}, triggers bug #244"); |
|---|
| | 100 | $total_langs = $langs+1; |
|---|
| | 101 | $class = get_class($object); |
|---|
| | 102 | $object_url = $_MIDCOM->get_host_prefix() . "__mfa/asgard/object/view/{$object->guid}/"; |
|---|
| | 103 | $msg = "Object <a target='_blank' href='{$object_url}'>{$class} #{$object->id}</a> has {$total_langs} languages, this triggers <a target='_blank' href='http://trac.midgard-project.org/ticket/244'>bug #244</a>."; |
|---|
| | 104 | $msg .= " Object will not be replicated, please go add one more language to the object in <a target='_blank' href='{$object_url}'>Asgard</a>."; |
|---|
| | 105 | $_MIDCOM->uimessages->add('midcom.helper.replicator', $msg, 'error'); |
|---|
| | 106 | $GLOBALS['midcom_helper_replicator_logger']->log_object($object, "has {$total_langs} languages, this triggers bug #244, preventing export.", MIDCOM_LOG_ERROR); |
|---|
| | 107 | unset($class, $object_url, $msg, $total_langs, $langs); |
|---|
| | 108 | //debug_pop(); |
|---|
| | 109 | return false; |
|---|
| | 110 | } |
|---|
| | 111 | /* |
|---|
| | 112 | debug_add("\$langs % 2 != 0, does not trigger bug #244"); |
|---|
| | 113 | debug_pop(); |
|---|
| | 114 | */ |
|---|
| | 115 | unset($langs); |
|---|
| | 116 | return $serialized; |
|---|