PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/standard/tags/release-1.0.0RC2a/scripts/manual/docbook/generage-wiki.php

https://github.com/bhaumik25/zend-framework
PHP | 337 lines | 270 code | 64 blank | 3 comment | 19 complexity | 05b6079e03b7f673822ec620bb55163a MD5 | raw file
  1. <?php
  2. error_reporting(E_ALL);
  3. require_once dirname(__FILE__) . '/config.php';
  4. require_once dirname(__FILE__) . '/library/Confluence/Book.php';
  5. require_once dirname(__FILE__) . '/library/Confluence/Chapter.php';
  6. $lng = isset($argv[1]) ? $argv[1] : 'en';
  7. $incubator = '';
  8. $stylesheet = dirname(__FILE__) . '/xsl/wiki.xsl';
  9. switch($lng) {
  10. case 'en':
  11. $space = 'ZFDOCDEV';
  12. break;
  13. case 'incubator':
  14. $space = 'ZFDOC';
  15. $lng = 'en';
  16. $incubator = 'incubator/';
  17. break;
  18. default:
  19. $space = 'DOCDEV' . strtoupper($lng);
  20. break;
  21. }
  22. $path = dirname(dirname(dirname(dirname(__FILE__)))) . '/documentation/manual/' . $lng . '/manual.xml.in';
  23. echo 'Running wikification';
  24. echo "\n\t date: " . date('Y-m-d H:i:s');
  25. echo "\n\t styleshet: " . $stylesheet;
  26. echo "\n\t language: " . $lng;
  27. echo "\n\t space: " . $space;
  28. echo "\n\t path: " . $path;
  29. $book = new Confluence_Book($path);
  30. $book = $book->get();
  31. $soap = new SoapClient('http://framework.zend.com/wiki/rpc/soap-axis/confluenceservice-v1?wsdl');
  32. $token = $soap->login($confluenceUser, $confluencePass);
  33. $home = $soap->getPage($token, $space, 'Home');
  34. $jira = new SoapClient('http://framework.zend.com/issues/rpc/soap/jirasoapservice-v2?wsdl');
  35. $jiraToken = $jira->login($jiraUser, $jiraPass);
  36. $_components = $jira->getComponents($jiraToken, 'ZF');
  37. $components = array();
  38. foreach($_components as $key => $component) {
  39. $components[$component->name] = $component->id;
  40. }
  41. $new = array();
  42. $prev = array();
  43. $compare = array();
  44. echo "\n\nChecking for appendix page ... ";
  45. try {
  46. $appendix = $soap->getPage($token, $space, 'Appendix');
  47. echo 'exists';
  48. } catch (Exception $e) {
  49. echo 'does not exist - creating';
  50. $page = new stdClass;
  51. $page->id = false;
  52. $page->version = 1;
  53. $page->permissions = true;
  54. $page->current = true;
  55. $page->homePage = false;
  56. $page->space = $space;
  57. $page->title = 'Appendix';
  58. $page->content = '{children}';
  59. $page->parentId = false;
  60. $soap->storePage($token, $page);
  61. $appendix = $soap->getPage($token, $space, 'Appendix');
  62. array_push($new, 'Appendix');
  63. }
  64. $current = $soap->getPages($token, $space);
  65. echo "\nQuerying current wiki pages: ";
  66. foreach ($current as $key => $wikiPage) {
  67. $key = md5($wikiPage->parentId . trim(substr($wikiPage->title, strpos($wikiPage->title, '. ') + 2)));
  68. $compare[$key] = $wikiPage;
  69. echo "\n\n\t title: " . $wikiPage->title;
  70. echo "\n\t hash: " . $key;
  71. array_push($prev, $wikiPage->title);
  72. }
  73. // process chapters
  74. $i = 0;
  75. foreach ($book->chapter as $chapter) {
  76. $i++;
  77. $mainChapter = new Confluence_Chapter($chapter, $i . '. ');
  78. $subChapter = new Confluence_Chapter($chapter->sect1[0], $i . '. ');
  79. $compareKey = md5($home->id . $mainChapter->getTitle(false));
  80. echo "\n\n" . $mainChapter->getTitle();
  81. echo "\n\t compare key: " . $compareKey;
  82. echo "\n\t page status: ";
  83. array_push($new, $mainChapter->getTitle());
  84. $wiki = $subChapter->getWiki($stylesheet);
  85. if (isset($components[$mainChapter->getTitle(false)])) {
  86. $wiki .= "\n\nh1. Jira issues\n";
  87. $wiki .= "{jiraissues:url=http://framework.zend.com/issues/secure/IssueNavigator.jspa?view=rss&&pid=10000&resolution=-1&component=" . $components[$mainChapter->getTitle(false)] . "&sorter/field=issuekey&sorter/order=DESC&tempMax=25&reset=true&decorator=none}\n\n{scrollbar}";
  88. }
  89. if (array_key_exists($compareKey, $compare)) {
  90. echo 'existing page - updating';
  91. $page = $soap->getPage($token, $space, $compare[$compareKey]->title);
  92. echo "\n\t queried page: " . $page->title;
  93. echo "\n\t page version: " . $page->version;
  94. echo "\n\t page parentId: " . $page->parentId;
  95. $page->permissions = true;
  96. $page->current = true;
  97. $page->homePage = false;
  98. $page->title = $mainChapter->getTitle();
  99. $page->content = $wiki;
  100. $page->parentId = $home->id;
  101. } else {
  102. echo 'new page - creating';
  103. $page = new stdClass;
  104. $page->id = false;
  105. $page->version = 1;
  106. $page->permissions = true;
  107. $page->current = true;
  108. $page->homePage = false;
  109. $page->space = $space;
  110. $page->title = $mainChapter->getTitle();
  111. $page->content = $wiki;
  112. $page->parentId = $home->id;
  113. }
  114. echo "\n\t storing status: ";
  115. try {
  116. $soap->storePage($token, $page);
  117. echo "success";
  118. } catch (Exception $e) {
  119. echo "failed - " . $e->getMessage();
  120. }
  121. try {
  122. $mainPage = $soap->getPage($token, $space, $mainChapter->getTitle());
  123. } catch (Exception $e) {
  124. continue;
  125. }
  126. $b = 0;
  127. $count = count($chapter->sect1)-1;
  128. for ($x = 1; $x <= $count; $x++) {
  129. $b += 0.1;
  130. $subChapter = new Confluence_Chapter($chapter->sect1[$x], $i+$b . '. ');
  131. $compareKey = md5($mainPage->id . $subChapter->getTitle(false));
  132. echo "\n\n" . $subChapter->getTitle();
  133. array_push($new, $subChapter->getTitle());
  134. if (array_key_exists($compareKey, $compare)) {
  135. echo ' existing page - updating';
  136. $page = $soap->getPage($token, $space, $compare[$compareKey]->title);
  137. echo "\n\t queried page: " . $page->title;
  138. echo "\n\t page version: " . $page->version;
  139. echo "\n\t page parentId: " . $page->parentId;
  140. $page->permissions = true;
  141. $page->current = true;
  142. $page->homePage = false;
  143. $page->title = $subChapter->getTitle();
  144. $page->content = $subChapter->getWiki($stylesheet);
  145. $page->parentId = $mainPage->id;
  146. } else {
  147. echo 'new page - creating';
  148. $page = new stdClass;
  149. $page->id = false;
  150. $page->version = 1;
  151. $page->permissions = true;
  152. $page->current = true;
  153. $page->homePage = false;
  154. $page->space = $space;
  155. $page->title = $subChapter->getTitle();
  156. $page->content = $subChapter->getWiki($stylesheet);
  157. $page->parentId = $mainPage->id;
  158. }
  159. echo "\n\t storing status: ";
  160. try {
  161. $soap->storePage($token, $page);
  162. echo "success";
  163. } catch (Exception $e) {
  164. echo "failed - " . $e->getMessage();
  165. }
  166. }
  167. }
  168. // process appendix
  169. $i = 0;
  170. foreach ($book->appendix as $chapter) {
  171. $i++;
  172. $mainChapter = new Confluence_Chapter($chapter, $i . '. ');
  173. $subChapter = new Confluence_Chapter($chapter->sect1[0], $i . '. ');
  174. $compareKey = md5($appendix->id . $mainChapter->getTitle(false));
  175. echo "\n\n" . $mainChapter->getTitle();
  176. echo "\n\t compare key: " . $compareKey;
  177. echo "\n\t page status: ";
  178. array_push($new, $mainChapter->getTitle());
  179. if (array_key_exists($compareKey, $compare)) {
  180. echo ' existing page - updating';
  181. $page = $soap->getPage($token, $space, $compare[$compareKey]->title);
  182. echo "\n\t queried page: " . $page->title;
  183. echo "\n\t page version: " . $page->version;
  184. echo "\n\t page parentId: " . $page->parentId;
  185. $page->permissions = true;
  186. $page->current = true;
  187. $page->homePage = false;
  188. $page->title = $mainChapter->getTitle();
  189. $page->content = $subChapter->getWiki($stylesheet);
  190. $page->parentId = $appendix->id;
  191. } else {
  192. echo 'new page - creating';
  193. $page = new stdClass;
  194. $page->id = false;
  195. $page->version = 1;
  196. $page->permissions = true;
  197. $page->current = true;
  198. $page->homePage = false;
  199. $page->space = $space;
  200. $page->title = $mainChapter->getTitle();
  201. $page->content = $subChapter->getWiki($stylesheet);
  202. $page->parentId = $appendix->id;
  203. }
  204. echo "\n\t storing status: ";
  205. try {
  206. $soap->storePage($token, $page);
  207. echo "success";
  208. } catch (Exception $e) {
  209. echo "failed - " . $e->getMessage();
  210. }
  211. try {
  212. $mainPage = $soap->getPage($token, $space, $mainChapter->getTitle());
  213. } catch (Exception $e) {
  214. continue;
  215. }
  216. $b = 0;
  217. $count = count($chapter->sect1)-1;
  218. for ($x = 1; $x <= $count; $x++) {
  219. $b += 0.1;
  220. $subChapter = new Confluence_Chapter($chapter->sect1[$x], $i+$b . '. ');
  221. $compareKey = md5($mainPage->id . $subChapter->getTitle(false));
  222. echo "\n\n" . $subChapter->getTitle();
  223. array_push($new, $subChapter->getTitle());
  224. if (array_key_exists($compareKey, $compare)) {
  225. echo 'existing page - updating';
  226. $page = $soap->getPage($token, $space, $compare[$compareKey]->title);
  227. echo "\n\t queried page: " . $page->title;
  228. echo "\n\t page version: " . $page->version;
  229. echo "\n\t page parentId: " . $page->parentId;
  230. $page->permissions = true;
  231. $page->current = true;
  232. $page->homePage = false;
  233. $page->title = $subChapter->getTitle();
  234. $page->content = $subChapter->getWiki($stylesheet);
  235. $page->parentId = $mainPage->id;
  236. } else {
  237. echo 'new page - creating';
  238. $page = new stdClass;
  239. $page->id = false;
  240. $page->version = 1;
  241. $page->permissions = true;
  242. $page->current = true;
  243. $page->homePage = false;
  244. $page->space = $space;
  245. $page->title = $subChapter->getTitle();
  246. $page->content = $subChapter->getWiki($stylesheet);
  247. $page->parentId = $mainPage->id;
  248. }
  249. echo "\n\t storing status: ";
  250. try {
  251. $soap->storePage($token, $page);
  252. echo "success";
  253. } catch (Exception $e) {
  254. echo "failed - " . $e->getMessage();
  255. }
  256. }
  257. }
  258. // remove deleted pages
  259. if (count($book->chapter)) {
  260. $diff = array_diff($prev, $new);
  261. foreach ($diff as $key => $pagename) {
  262. if ($pagename != 'Home' && $pagename != 'manual-template' && $pagename != 'Appendix') {
  263. echo 'Removing ' . $pagename . "\n";
  264. try {
  265. $page = $soap->getPage($token, $space, $pagename);
  266. $soap->removePage($token, $page->id);
  267. } catch (Exception $e) {
  268. continue;
  269. }
  270. }
  271. }
  272. }
  273. ?>