basic support for clone syncing of wikis and wiki pages
This commit is contained in:
parent
3bafa05ad1
commit
17f1d39fcf
@ -93,13 +93,25 @@ class NativeWiki {
|
|||||||
|
|
||||||
if($item_id) {
|
if($item_id) {
|
||||||
\Zotlabs\Daemon\Master::Summon(array('Notifier', 'activity', $item_id));
|
\Zotlabs\Daemon\Master::Summon(array('Notifier', 'activity', $item_id));
|
||||||
return array('item' => $post['item'], 'success' => true);
|
return array('item' => $post['item'], 'item_id' => $item_id, 'success' => true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return array('item' => null, 'success' => false);
|
return array('item' => null, 'success' => false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public function sync_a_wiki_item($uid,$id) {
|
||||||
|
$r = q("select * from item where id = %d and uid = %d",
|
||||||
|
intval($id),
|
||||||
|
intval($uid)
|
||||||
|
);
|
||||||
|
if($r) {
|
||||||
|
xchan_query($r);
|
||||||
|
$sync_item = fetch_post_tags($r);
|
||||||
|
build_sync_packet($uid,array('wiki' => array(encode_item($sync_item[0],true))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function delete_wiki($channel_id,$observer_hash,$resource_id) {
|
function delete_wiki($channel_id,$observer_hash,$resource_id) {
|
||||||
|
|
||||||
$w = self::get_wiki($channel_id,$observer_hash,$resource_id);
|
$w = self::get_wiki($channel_id,$observer_hash,$resource_id);
|
||||||
@ -113,7 +125,7 @@ class NativeWiki {
|
|||||||
|
|
||||||
info( t('Wiki files deleted successfully'));
|
info( t('Wiki files deleted successfully'));
|
||||||
|
|
||||||
return array('item' => $item, 'success' => (($drop === 1) ? true : false));
|
return array('item' => $item, 'item_id' => $item['id'], 'success' => (($drop === 1) ? true : false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,8 +61,9 @@ class NativeWikiPage {
|
|||||||
|
|
||||||
set_iconfig($arr,'nwikipage','pagetitle',urlencode(($name) ? $name : t('(No Title)')),true);
|
set_iconfig($arr,'nwikipage','pagetitle',urlencode(($name) ? $name : t('(No Title)')),true);
|
||||||
|
|
||||||
post_activity_item($arr, false, false);
|
$p = post_activity_item($arr, false, false);
|
||||||
|
|
||||||
|
if($p['success']) {
|
||||||
$page = [
|
$page = [
|
||||||
'rawName' => $name,
|
'rawName' => $name,
|
||||||
'htmlName' => escape_tags($name),
|
'htmlName' => escape_tags($name),
|
||||||
@ -70,7 +71,9 @@ class NativeWikiPage {
|
|||||||
'fileName' => urlencode(escape_tags($name)) . Zlib\NativeWikiPage::get_file_ext($w)
|
'fileName' => urlencode(escape_tags($name)) . Zlib\NativeWikiPage::get_file_ext($w)
|
||||||
];
|
];
|
||||||
|
|
||||||
return array('page' => $page, 'wiki' => $w, 'message' => '', 'success' => true);
|
return array('page' => $page, 'item_id' => $p['post_id'], 'wiki' => $w, 'message' => '', 'success' => true);
|
||||||
|
}
|
||||||
|
return [ 'success' => false, 'message' => t('Wiki page create failed.') ];
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function rename_page($arr) {
|
static public function rename_page($arr) {
|
||||||
@ -119,7 +122,7 @@ class NativeWikiPage {
|
|||||||
return [ 'success' => true, 'page' => $page ];
|
return [ 'success' => true, 'page' => $page ];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [ 'success' => false, 'message' => t('Page not found') ];
|
return [ 'success' => false, 'item_id' => $c['item_id'], 'message' => t('Page not found') ];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +361,7 @@ class NativeWikiPage {
|
|||||||
$ret = item_store($item, false, false);
|
$ret = item_store($item, false, false);
|
||||||
|
|
||||||
if($ret['item_id'])
|
if($ret['item_id'])
|
||||||
return array('message' => '', 'filename' => $filename, 'success' => true);
|
return array('message' => '', 'item_id' => $ret['item_id'], 'filename' => $filename, 'success' => true);
|
||||||
else
|
else
|
||||||
return array('message' => t('Page update failed.'), 'success' => false);
|
return array('message' => t('Page update failed.'), 'success' => false);
|
||||||
}
|
}
|
||||||
@ -490,7 +493,7 @@ class NativeWikiPage {
|
|||||||
|
|
||||||
if($page) {
|
if($page) {
|
||||||
set_iconfig($page['id'],'nwikipage','commit_msg',escape_tags($commit_msg),true);
|
set_iconfig($page['id'],'nwikipage','commit_msg',escape_tags($commit_msg),true);
|
||||||
return [ 'success' => true, 'page' => $page ];
|
return [ 'success' => true, 'item_id' => $page['id'], 'page' => $page ];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [ 'success' => false, 'message' => t('Page not found.') ];
|
return [ 'success' => false, 'message' => t('Page not found.') ];
|
||||||
|
@ -473,6 +473,9 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
if(is_array($data['menu']))
|
if(is_array($data['menu']))
|
||||||
import_menus($channel,$data['menu']);
|
import_menus($channel,$data['menu']);
|
||||||
|
|
||||||
|
if(is_array($data['wiki']))
|
||||||
|
import_items($channel,$data['wiki'],false,$relocate);
|
||||||
|
|
||||||
$addon = array('channel' => $channel,'data' => $data);
|
$addon = array('channel' => $channel,'data' => $data);
|
||||||
call_hooks('import_channel',$addon);
|
call_hooks('import_channel',$addon);
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
$o = profile_tabs($a, $is_owner, \App::$profile['channel_address']);
|
$o = profile_tabs($a, $is_owner, \App::$profile['channel_address']);
|
||||||
|
|
||||||
// Download a wiki
|
// Download a wiki
|
||||||
|
/*
|
||||||
if((argc() > 3) && (argv(2) === 'download') && (argv(3) === 'wiki')) {
|
if((argc() > 3) && (argv(2) === 'download') && (argv(3) === 'wiki')) {
|
||||||
|
|
||||||
$resource_id = argv(4);
|
$resource_id = argv(4);
|
||||||
@ -144,7 +144,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
killme();
|
killme();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
switch(argc()) {
|
switch(argc()) {
|
||||||
case 2:
|
case 2:
|
||||||
$wikis = Zlib\NativeWiki::listwikis($owner, get_observer_hash());
|
$wikis = Zlib\NativeWiki::listwikis($owner, get_observer_hash());
|
||||||
@ -361,6 +361,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
$acl->set_from_array($_POST);
|
$acl->set_from_array($_POST);
|
||||||
$r = Zlib\NativeWiki::create_wiki($owner, $observer_hash, $wiki, $acl);
|
$r = Zlib\NativeWiki::create_wiki($owner, $observer_hash, $wiki, $acl);
|
||||||
if($r['success']) {
|
if($r['success']) {
|
||||||
|
Zlib\NativeWiki::sync_a_wiki_item($owner['channel_id'],$r['item_id']);
|
||||||
$homePage = Zlib\NativeWikiPage::create_page($owner['channel_id'],$observer_hash,'Home', $r['item']['resource_id']);
|
$homePage = Zlib\NativeWikiPage::create_page($owner['channel_id'],$observer_hash,'Home', $r['item']['resource_id']);
|
||||||
if(! $homePage['success']) {
|
if(! $homePage['success']) {
|
||||||
notice( t('Wiki created, but error creating Home page.'));
|
notice( t('Wiki created, but error creating Home page.'));
|
||||||
@ -386,6 +387,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
$resource_id = $_POST['resource_id'];
|
$resource_id = $_POST['resource_id'];
|
||||||
$deleted = Zlib\NativeWiki::delete_wiki($owner['channel_id'],$observer_hash,$resource_id);
|
$deleted = Zlib\NativeWiki::delete_wiki($owner['channel_id'],$observer_hash,$resource_id);
|
||||||
if ($deleted['success']) {
|
if ($deleted['success']) {
|
||||||
|
Zlib\NativeWiki::sync_a_wiki_item($owner['channel_id'],$deleted['item_id']);
|
||||||
json_return_and_die(array('message' => '', 'success' => true));
|
json_return_and_die(array('message' => '', 'success' => true));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -425,11 +427,14 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
));
|
));
|
||||||
|
|
||||||
if($commit['success']) {
|
if($commit['success']) {
|
||||||
|
Zlib\NativeWiki::sync_a_wiki_item($owner['channel_id'],$commit['item_id']);
|
||||||
json_return_and_die(array('url' => '/' . argv(0) . '/' . argv(1) . '/' . $page['wiki']['urlName'] . '/' . $page['page']['urlName'], 'success' => true));
|
json_return_and_die(array('url' => '/' . argv(0) . '/' . argv(1) . '/' . $page['wiki']['urlName'] . '/' . $page['page']['urlName'], 'success' => true));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
json_return_and_die(array('message' => 'Error making git commit','url' => '/' . argv(0) . '/' . argv(1) . '/' . $page['wiki']['urlName'] . '/' . urlencode($page['page']['urlName']),'success' => false));
|
json_return_and_die(array('message' => 'Error making git commit','url' => '/' . argv(0) . '/' . argv(1) . '/' . $page['wiki']['urlName'] . '/' . urlencode($page['page']['urlName']),'success' => false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger('Error creating page');
|
logger('Error creating page');
|
||||||
@ -487,6 +492,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
));
|
));
|
||||||
|
|
||||||
if($commit['success']) {
|
if($commit['success']) {
|
||||||
|
Zlib\NativeWiki::sync_a_wiki_item($owner['channel_id'],$commit['item_id']);
|
||||||
json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
|
json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -549,6 +555,7 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
'files' => null
|
'files' => null
|
||||||
));
|
));
|
||||||
if($commit['success']) {
|
if($commit['success']) {
|
||||||
|
Zlib\NativeWiki::sync_a_wiki_item($owner['channel_id'],$commit['item_id']);
|
||||||
json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
|
json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -563,7 +570,6 @@ class Wiki extends \Zotlabs\Web\Controller {
|
|||||||
// Revert a page
|
// Revert a page
|
||||||
if ((argc() === 4) && (argv(2) === 'revert') && (argv(3) === 'page')) {
|
if ((argc() === 4) && (argv(2) === 'revert') && (argv(3) === 'page')) {
|
||||||
|
|
||||||
logger('revert was called: ' . print_r($_POST,true));
|
|
||||||
$resource_id = $_POST['resource_id'];
|
$resource_id = $_POST['resource_id'];
|
||||||
$pageUrlName = $_POST['name'];
|
$pageUrlName = $_POST['name'];
|
||||||
$commitHash = $_POST['commitHash'];
|
$commitHash = $_POST['commitHash'];
|
||||||
@ -637,6 +643,7 @@ logger('revert was called: ' . print_r($_POST,true));
|
|||||||
));
|
));
|
||||||
|
|
||||||
if($commit['success']) {
|
if($commit['success']) {
|
||||||
|
Zlib\NativeWiki::sync_a_wiki_item($owner['channel_id'],$commit['item_id']);
|
||||||
json_return_and_die(array('name' => $renamed['page'], 'message' => 'Wiki git repo commit made', 'success' => true));
|
json_return_and_die(array('name' => $renamed['page'], 'message' => 'Wiki git repo commit made', 'success' => true));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -671,6 +671,17 @@ function identity_basic_export($channel_id, $items = false) {
|
|||||||
$ret['mail'] = $m;
|
$ret['mail'] = $m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$r = q("select * from item where resource_type like 'nwiki%%' and uid = %d order by created",
|
||||||
|
intval($channel_id)
|
||||||
|
);
|
||||||
|
if($r) {
|
||||||
|
$ret['wiki'] = array();
|
||||||
|
xchan_query($r);
|
||||||
|
$r = fetch_post_tags($r,true);
|
||||||
|
foreach($r as $rv) {
|
||||||
|
$ret['wiki'][] = encode_item($rv,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** @warning this may run into memory limits on smaller systems */
|
/** @warning this may run into memory limits on smaller systems */
|
||||||
|
|
||||||
|
@ -391,6 +391,7 @@ function post_activity_item($arr,$allow_code = false,$deliver = true) {
|
|||||||
call_hooks('post_local_end', $arr);
|
call_hooks('post_local_end', $arr);
|
||||||
Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$post_id));
|
Zotlabs\Daemon\Master::Summon(array('Notifier','activity',$post_id));
|
||||||
$ret['success'] = true;
|
$ret['success'] = true;
|
||||||
|
$ret['item_id'] = $post_id;
|
||||||
$ret['activity'] = $post['item'];
|
$ret['activity'] = $post['item'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3174,8 +3174,11 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
|
|||||||
if(array_key_exists('menu',$arr) && $arr['menu'])
|
if(array_key_exists('menu',$arr) && $arr['menu'])
|
||||||
sync_menus($channel,$arr['menu']);
|
sync_menus($channel,$arr['menu']);
|
||||||
|
|
||||||
if(array_key_exists('file',$arr) && $arr['file'])
|
if(array_key_exists('menu',$arr) && $arr['menu'])
|
||||||
sync_files($channel,$arr['file']);
|
sync_menus($channel,$arr['menu']);
|
||||||
|
|
||||||
|
if(array_key_exists('wiki',$arr) && $arr['wiki'])
|
||||||
|
sync_items($channel,$arr['wiki']);
|
||||||
|
|
||||||
if(array_key_exists('channel',$arr) && is_array($arr['channel']) && count($arr['channel'])) {
|
if(array_key_exists('channel',$arr) && is_array($arr['channel']) && count($arr['channel'])) {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user