示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $profileName = $input->getArgument('profile');
     $repository = $input->getArgument('repository');
     $force = $input->getOption('force');
     $profile = \Tiki_Profile::fromNames($repository, $profileName);
     if (!$profile) {
         $output->writeln('<error>Profile not found.</error>');
         return;
     }
     $tikilib = \TikiLib::lib('tiki');
     $installer = new \Tiki_Profile_Installer();
     $isInstalled = $installer->isInstalled($profile);
     if ($isInstalled && $force) {
         $installer->forget($profile);
         $isInstalled = false;
     }
     if (!$isInstalled) {
         $transaction = $tikilib->begin();
         if ($installer->install($profile)) {
             $transaction->commit();
             $output->writeln('Profile applied.');
         } else {
             $output->writeln("<error>Installation failed:</error>");
             foreach ($installer->getFeedback() as $error) {
                 $output->writeln("<error>{$error}</error>");
             }
         }
     } else {
         $output->writeln('<info>Profile was already applied. Nothing happened.</info>');
     }
 }
示例#2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $addon_utilities = new \TikiAddons_Utilities();
     $addonName = $input->getArgument('addon');
     if (strpos($addonName, '/') !== false && strpos($addonName, '_') === false) {
         $package = $addonName;
         $folder = str_replace('/', '_', $addonName);
     } else {
         $package = str_replace('_', '/', $addonName);
         $folder = $addonName;
     }
     $repository = 'file://addons/' . $folder . '/profiles';
     $reapply = $input->getOption('reapply');
     $ignoredepends = $input->getOption('ignoredepends');
     if (empty(glob(TIKI_PATH . '/addons/' . $folder . '/profiles/*.yml'))) {
         $output->writeln("<error>No profiles found.</error>");
         return false;
     }
     if (!$ignoredepends) {
         $addon_utilities->checkDependencies($folder);
     }
     $addons = \TikiAddons::getInstalled();
     $tikilib = \TikiLib::lib('tiki');
     $installer = new \Tiki_Profile_Installer();
     foreach (glob(TIKI_PATH . '/addons/' . $folder . '/profiles/*.yml') as $file) {
         $profileName = str_replace('.yml', '', basename($file));
         $profile = \Tiki_Profile::fromNames($repository, $profileName);
         if (!$profile) {
             $output->writeln("<error>Profile {$profileName} not found.</error>");
             continue;
         }
         $isInstalled = $installer->isInstalled($profile);
         if ($isInstalled && $reapply) {
             $installer->forget($profile);
             $isInstalled = false;
         }
         if (!$isInstalled) {
             $transaction = $tikilib->begin();
             if ($installer->install($profile)) {
                 $addon_utilities->updateProfile($folder, $addons[$package]->version, $profileName);
                 $transaction->commit();
                 $output->writeln("Profile {$profileName} applied.");
             } else {
                 $output->writeln("<error>Profile {$profileName} installation failed:</error>");
                 foreach ($installer->getFeedback() as $error) {
                     $output->writeln("<error>{$error}</error>");
                 }
             }
         } else {
             $output->writeln("<info>Profile {$profileName} was already applied. Nothing happened.</info>");
         }
     }
 }
示例#3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $addon_utilities = new \TikiAddons_Utilities();
     $addonName = $input->getArgument('addon');
     if (strpos($addonName, '/') !== false && strpos($addonName, '_') === false) {
         $package = $addonName;
         $folder = str_replace('/', '_', $addonName);
     } else {
         $package = str_replace('_', '/', $addonName);
         $folder = $addonName;
     }
     $repository = 'file://addons/' . $folder . '/profiles';
     $ignoredepends = $input->getOption('ignoredepends');
     $confirm = $input->getOption('confirm');
     if (empty(glob(TIKI_PATH . '/addons/' . $folder . '/profiles/*.yml'))) {
         $output->writeln("<error>No profiles found.</error>");
         return;
     }
     if (!$ignoredepends) {
         $addon_utilities->checkDependencies($folder);
     }
     $upgradeInfo = json_decode(file_get_contents(TIKI_PATH . '/addons/' . $folder . '/upgrade.json'));
     $validVersions = array();
     foreach ($upgradeInfo as $version => $info) {
         $validVersions[] = $version;
     }
     $config = null;
     $lastVersionInstalled = $addon_utilities->getLastVersionInstalled($folder);
     $reapplyProfiles = array();
     $forgetProfiles = array();
     $removeItems = array();
     foreach ($validVersions as $v) {
         if ($addon_utilities->checkVersionMatch($lastVersionInstalled, $v)) {
             $config = $upgradeInfo->{$v};
             $removeItems = $config->remove;
             $forgetProfiles = $config->forget;
             $reapplyProfiles = $config->reapply;
             break;
         }
     }
     $addons = \TikiAddons::getInstalled();
     if (!$config) {
         if (strnatcmp($lastVersionInstalled, $addons[$package]->version) <= 0) {
             $output->writeln("<error>Currently installed version ({$lastVersionInstalled}) is already up to date.</error>");
         } else {
             $output->writeln("<error>No valid versions currently installed to upgrade found.</error>");
         }
         return false;
     }
     $installedProfiles = $addon_utilities->getInstalledProfiles($folder);
     $installedProfileNames = array_keys($installedProfiles);
     $willRemove = false;
     foreach ($removeItems as $remove) {
         if (empty($remove->profile)) {
             $profile = '';
         } else {
             $profile = $remove->profile;
         }
         $objectId = $addon_utilities->getObjectId($folder, $remove->ref, $profile);
         $objectType = $remove->type;
         if ($objectId) {
             if ($confirm) {
                 $addon_utilities->removeObject($objectId, $objectType);
                 $output->writeln("{$objectType} '{$objectId}' has been deleted.");
             } else {
                 $output->writeln("<info>{$objectType} '{$objectId}' will be deleted.</info>");
             }
             $willRemove = true;
         }
     }
     $tikilib = \TikiLib::lib('tiki');
     $installer = new \Tiki_Profile_Installer();
     // First forget profiles that need to be forgotten
     foreach ($forgetProfiles as $toForget) {
         if (in_array($toForget, $installedProfileNames)) {
             if ($confirm || !$willRemove) {
                 $addon_utilities->forgetProfileAllVersions($folder, $toForget);
                 $profile = \Tiki_Profile::fromNames($repository, $toForget);
                 if (!$profile) {
                     $output->writeln("<error>Profile {$toForget} not found.</error>");
                 } else {
                     $installer->forget($profile);
                 }
             } else {
                 $output->writeln("<info>The installed profile {$toForget} will be forgotten.</info>");
             }
         }
     }
     if (!$confirm && $willRemove) {
         $output->writeln("<error>There will be NO undo, and all data in the above objects will be deleted as part of the upgrade.</error>");
         $output->writeln("<info>Use the --confirm option to proceed with removal and upgrade.</info>");
     }
     if ($confirm || !$willRemove) {
         // Finally install profiles
         foreach (glob(TIKI_PATH . '/addons/' . $folder . '/profiles/*.yml') as $file) {
             $profileName = str_replace('.yml', '', basename($file));
             $profile = \Tiki_Profile::fromNames($repository, $profileName);
             if (in_array($profileName, $reapplyProfiles)) {
                 $reapply = true;
             } else {
                 $reapply = false;
             }
             if (!$profile) {
                 $output->writeln("<error>Profile {$profileName} not found.</error>");
                 continue;
             }
             $isInstalled = $installer->isInstalled($profile);
             if ($isInstalled && $reapply) {
                 $installer->forget($profile);
                 $isInstalled = false;
             }
             if (!$isInstalled) {
                 $transaction = $tikilib->begin();
                 if ($installer->install($profile)) {
                     $addon_utilities->updateProfile($folder, $addons[$package]->version, $profileName);
                     $transaction->commit();
                     $output->writeln("Profile {$profileName} applied.");
                 } else {
                     $output->writeln("<error>Profile {$profileName} installation failed:</error>");
                     foreach ($installer->getFeedback() as $error) {
                         $output->writeln("<error>{$error}</error>");
                     }
                 }
             } else {
                 $output->writeln("<info>Profile {$profileName} was already applied. Nothing happened.</info>");
             }
         }
     }
 }
function wikiplugin_datachannel($data, $params)
{
    static $execution = 0;
    global $prefs, $smarty, $headerlib;
    $executionId = 'datachannel-exec-' . ++$execution;
    if (isset($params['price']) && $params['price'] == 0) {
        // Convert things like 0.00 to empty
        unset($params['price']);
    }
    $fields = array();
    $inputfields = array();
    $lines = explode("\n", $data);
    $lines = array_map('trim', $lines);
    $lines = array_filter($lines);
    $js = '';
    if (!isset($params['array_values'])) {
        $params['array_values'] = 'n';
    }
    foreach ($lines as $line) {
        $parts = explode(',', $line, 2);
        $parts = array_map('trim', $parts);
        if (count($parts) == 2) {
            if (strpos($parts[1], 'external') === 0) {
                // e.g. "fieldid,external=fieldname"
                $moreparts = explode('=', $parts[1], 2);
                $moreparts = array_map('trim', $moreparts);
                if (count($moreparts) < 2) {
                    $moreparts[1] = $parts[0];
                    // no fieldname supplied so use same as fieldid
                }
                $fields[$parts[0]] = $moreparts[0];
                if ($params['array_values'] === 'y' && preg_match('/[\\[\\]\\.#\\=]/', $moreparts[1])) {
                    // check for [ ] = or . which would be a jQuery selector
                    // might select multiple inputs
                    $js .= "\n" . '$("input[name=\'' . $parts[0] . '\']").val( unescape($("' . $moreparts[1] . '").serialize()));';
                } else {
                    // otherwise it's an id
                    $js .= "\n" . '$("input[name=\'' . $parts[0] . '\']").val( unescape($("#' . $moreparts[1] . '").val()));';
                }
                $inputfields[$parts[0]] = 'external';
            } elseif (strpos($parts[1], 'hidden') === 0) {
                $moreparts = explode('=', $parts[1], 2);
                $moreparts = array_map('trim', $moreparts);
                $fields[$parts[0]] = $moreparts[1];
                $inputfields[$parts[0]] = 'hidden';
            } else {
                $fields[$parts[0]] = $parts[1];
                $inputfields[$parts[0]] = $parts[1];
            }
        }
    }
    $groups = Perms::get()->getGroups();
    $config = Tiki_Profile_ChannelList::fromConfiguration($prefs['profile_channels']);
    if ($config->canExecuteChannels(array($params['channel']), $groups, true)) {
        $smarty->assign('datachannel_execution', $executionId);
        if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['datachannel_execution']) && $_POST['datachannel_execution'] == $executionId && $config->canExecuteChannels(array($params['channel']), $groups)) {
            $input = array_intersect_key(array_map('trim', $_POST), $inputfields);
            $itemIds = array();
            // process possible arrays in post
            if ($params['array_values'] === 'y') {
                foreach ($input as $key => $val) {
                    if (!empty($val)) {
                        parse_str($val, $vals);
                        if (is_array($vals)) {
                            // serialized collection of inputs
                            $arr = array();
                            if ($key == 'itemId') {
                                foreach ($vals as $v) {
                                    // itemId[x,y,z]
                                    if (is_array($v)) {
                                        $arr = array_merge($arr, $v);
                                    }
                                }
                                $itemIds = $arr;
                            } else {
                                foreach ($vals as $v) {
                                    // fieldname[x=>a,y=>b,z=>c]
                                    if (is_array($v)) {
                                        foreach ($v as $k => $kv) {
                                            if (in_array($k, $itemIds)) {
                                                // check if sent in itemIds array
                                                $arr[] = $kv;
                                                // (e.g. from trackerlist checkboxes)
                                            }
                                        }
                                    } else {
                                        $arr = $val;
                                        // not an array, so use the initial string val
                                    }
                                }
                            }
                            $input[$key] = $arr;
                        }
                    }
                }
            }
            $inputs = array();
            if ($params['array_values'] === 'y' && !empty($itemIds)) {
                $cid = count($itemIds);
                for ($i = 0; $i < $cid; $i++) {
                    // reorganise array
                    $arr = array();
                    foreach (array_keys($input) as $k) {
                        if (isset($input[$k]) && is_array($input[$k])) {
                            $arr[$k] = $input[$k][$i];
                        } else {
                            $arr[$k] = $input[$k];
                        }
                    }
                    $inputs[] = $arr;
                }
            } else {
                $inputs[] = $input;
            }
            $static = $params;
            $unsets = wikiplugin_datachannel_info();
            // get defined params
            $unsets = array_keys($unsets['params']);
            foreach ($unsets as $un) {
                // remove defined params leaving user supplied ones
                unset($static[$un]);
            }
            if (!empty($params['price'])) {
                global $paymentlib;
                require_once 'lib/payment/paymentlib.php';
                $desc = empty($params['paymentlabel']) ? tr('Datachannel:', $prefs['site_language']) . ' ' . $params['channel'] : $params['paymentlabel'];
                $posts = array();
                foreach ($input as $key => $post) {
                    $posts[$key] = $post;
                    $desc .= '/' . $post;
                }
                $id = $paymentlib->request_payment($desc, $params['price'], $prefs['payment_default_delay']);
                $paymentlib->register_behavior($id, 'complete', 'execute_datachannel', array($data, $params, $posts, $executionId));
                require_once 'lib/smarty_tiki/function.payment.php';
                return '^~np~' . smarty_function_payment(array('id' => $id), $smarty) . '~/np~^';
            }
            foreach ($inputs as $input) {
                $userInput = array_merge($input, $static);
                Tiki_Profile::useUnicityPrefix(uniqid());
                $profiles = $config->getProfiles(array($params['channel']));
                $profile = reset($profiles);
                $profile->removeSymbols();
                Tiki_Profile::useUnicityPrefix(uniqid());
                $installer = new Tiki_Profile_Installer();
                //TODO: What is the following line for? Future feature to limit capabilities of data channels?
                //$installer->limitGlobalPreferences( array() );
                // jb tiki6: looks like if set to an empty array it would prevent any prefs being set
                // i guess the idea is to be able to restrict the settable prefs to only harmless ones for security
                $installer->setUserData($userInput);
                if (!empty($params['debug']) && $params['debug'] === 'y') {
                    $installer->setDebug();
                }
                $params['emptyCache'] = isset($params['emptyCache']) ? $params['emptyCache'] : 'all';
                $installer->install($profile, $params['emptyCache']);
            }
            if (empty($params['returnURI'])) {
                $params['returnURI'] = $_SERVER['HTTP_REFERER'];
            }
            // default to return to same page
            if (empty($params['debug']) || $params['debug'] != 'y') {
                if (isset($params['quietReturn']) && $params['quietReturn'] == 'y') {
                    return true;
                } else {
                    header('Location: ' . $params['returnURI']);
                }
                die;
            }
            $smarty->assign('datachannel_feedbacks', array_merge($installer->getFeedback(), $profile->getFeedback()));
        }
        $smarty->assign('datachannel_inputfields', $inputfields);
        $smarty->assign('datachannel_fields', $fields);
        $smarty->assign('button_label', !empty($params['buttonLabel']) ? $params['buttonLabel'] : 'Go');
        $smarty->assign('form_class_attr', !empty($params['class']) ? ' class="' . $params['class'] . '"' : '');
        if (!empty($js)) {
            $headerlib->add_js("function datachannel_form_submit{$execution}() {{$js}\nreturn true;\n}");
            $smarty->assign('datachannel_form_onsubmit', ' onsubmit="return datachannel_form_submit' . $execution . '();"');
        } else {
            $smarty->assign('datachannel_form_onsubmit', '');
        }
        return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_datachannel.tpl') . '~/np~';
    }
}
示例#5
0
     $test_source = str_replace('<x>', '', $test_source);
     $smarty->assign('test_source', $test_source);
     $smarty->assign('profile_tester_name', $_POST['profile_tester_name']);
     $profile = Tiki_Profile::fromString($test_source, $_POST['profile_tester_name']);
     $profile->removeSymbols();
     $installer = new Tiki_Profile_Installer();
     $empty_cache = $_REQUEST['empty_cache'];
     $smarty->assign('empty_cache', $empty_cache);
     $installer->install($profile, $empty_cache);
     if ($target = $profile->getInstructionPage()) {
         $wikilib = TikiLib::lib('wiki');
         $target = $wikilib->sefurl($target);
         header('Location: ' . $target);
         exit;
     } else {
         $profilefeedback = $installer->getFeedback();
         if (count($profilefeedback) > 0) {
             $smarty->assign_by_ref('profilefeedback', $profilefeedback);
         }
     }
 }
 // }}}
 if (isset($_GET['refresh'])) {
     $toRefresh = (int) $_GET['refresh'];
     if (isset($sources[$toRefresh])) {
         echo json_encode(array('status' => $list->refreshCache($sources[$toRefresh]['url']) ? 'open' : 'closed', 'lastupdate' => date('Y-m-d H:i:s')));
     } else {
         echo '{}';
     }
     exit;
 }
示例#6
0
 public function action_import_profile($input)
 {
     $tikilib = TikiLib::lib('tiki');
     $perms = Perms::get();
     if (!$perms->admin) {
         throw new Services_Exception_Denied(tr('Reserved for administrators'));
     }
     unset($success);
     $confirm = $input->confirm->int();
     if ($confirm) {
         $transaction = $tikilib->begin();
         $installer = new Tiki_Profile_Installer();
         $yaml = $input->yaml->string();
         $name = "tracker_import:" . md5($yaml);
         $profile = Tiki_Profile::fromString('{CODE(caption="yaml")}' . "\n" . $yaml . "\n" . '{CODE}', $name);
         if ($installer->isInstallable($profile) == true) {
             if ($installer->isInstalled($profile) == true) {
                 $installer->forget($profile);
             }
             $installer->install($profile);
             $feedback = $installer->getFeedback();
             $transaction->commit();
             return $feedback;
             $success = 1;
         } else {
             return false;
         }
     }
     return array('title' => tr('Import Tracker From Profile/YAML'), 'modal' => $input->modal->int());
 }
         $test_source = "{CODE(caption=>YAML)}\n{$test_source}\n{CODE}";
     }
     $smarty->assign('test_source', $test_source);
     $smarty->assign('profile_tester_name', $_POST['profile_tester_name']);
     $profile = Tiki_Profile::fromString($test_source, $_POST['profile_tester_name']);
     $profile->removeSymbols();
     $installer = new Tiki_Profile_Installer();
     $installer->install($profile);
     if ($target = $profile->getInstructionPage()) {
         global $wikilib;
         require_once 'lib/wiki/wikilib.php';
         $target = $wikilib->sefurl($target);
         header('Location: ' . $target);
         exit;
     } else {
         if (count($installer->getFeedback()) > 0) {
             $smarty->assign_by_ref('profilefeedback', $installer->getFeedback());
         }
     }
 }
 // }}}
 if (isset($_GET['refresh'])) {
     // {{{
     $toRefresh = (int) $_GET['refresh'];
     if (isset($sources[$toRefresh])) {
         echo json_encode(array('status' => $list->refreshCache($sources[$toRefresh]['url']) ? 'open' : 'closed', 'lastupdate' => date('Y-m-d H:i:s')));
     } else {
         echo '{}';
     }
     exit;
 }
示例#8
0
 public function action_import_profile($input)
 {
     global $tikilib, $access;
     $access->check_permission('tiki_p_admin');
     $transaction = $tikilib->begin();
     $installer = new Tiki_Profile_Installer();
     $yaml = $input->yaml->string();
     $name = "tracker_import:" . md5($yaml);
     $profile = Tiki_Profile::fromString('{CODE(caption="yaml")}' . "\n" . $yaml . "\n" . '{CODE}', $name);
     if ($installer->isInstallable($profile) == true) {
         if ($installer->isInstalled($profile) == true) {
             $installer->forget($profile);
         }
         $installer->install($profile);
         $feedback = $installer->getFeedback();
         $transaction->commit();
         return $feedback;
     } else {
         return false;
     }
 }