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>'); } }
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>"); } } }
function wikiplugin_profile( $data, $params ) { require_once 'lib/profilelib/profilelib.php'; require_once 'lib/profilelib/installlib.php'; global $tiki_p_admin; if ( $tiki_p_admin != 'y' ) { return '__' . tra('Profile plugin only available to administrators') . '__'; } $params = array_merge(array('domain' => 'profiles.tiki.org'), $params); if ( !isset( $params['name'] ) ) { return 'Missing parameter __name__'; } $profile = Tiki_Profile::fromNames($params['domain'], $params['name']); if ( $profile ) { $installer = new Tiki_Profile_Installer; try { if ( $installer->isInstalled($profile) ) { if ( $_POST['reinstall'] == "{$params['domain']}/{$params['name']}" ) { $installer->forget($profile); $installer->install($profile); header('Location: ' . $_SERVER['REQUEST_URI']); exit; } } else { if ( $_POST['install'] == "{$params['domain']}/{$params['name']}" ) { $installer->install($profile); header('Location: ' . $_SERVER['REQUEST_URI']); exit; } } } catch( Exception $e ) { return '__' . $e->getMessage() . '__'; } global $smarty; $smarty->assign('profile_is_installed', $installer->isInstalled($profile)); $smarty->assign('profile_key', "{$params['domain']}/{$params['name']}"); return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_profile.tpl') . '~/np~'; } else { return '__' . tr('Profile %0/%1 not found', $params['domain'], $params['name']) . '__'; } }
protected function execute(InputInterface $input, OutputInterface $output) { $profileName = $input->getArgument('profile'); $repository = $input->getArgument('repository'); $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) { $transaction = $tikilib->begin(); $installer->forget($profile); $transaction->commit(); $output->writeln('Profile forgotten.'); } else { $output->writeln('<info>Profile was not installed or did not create any objects.</info>'); } }
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>"); } } } }
'tiki-channel.php', tra('One of the requested channels cannot be requested. It does not exist or permission is denied.') ); } $profiles = $config->getProfiles($channels); if ( count($profiles) != count($channels) ) { $access->display_error('tiki-channel.php', tra('One of the install profiles could not be obtained.')); } Tiki_Profile::useUnicityPrefix(uniqid()); $installer = new Tiki_Profile_Installer; $installer->limitGlobalPreferences(array()); foreach ( $calls as $call ) { list($channel, $userInput) = $call; // Profile can be installed multiple times // Only last values preserved $profile = $profiles[$channel]; $installer->forget($profile); $installer->setUserData($userInput); $installer->install($profile); } if ( isset($_REQUEST['return_uri']) ) { header("Location: {$_REQUEST['return_uri']}"); }
function request_payment() { global $prefs, $user; $tikilib = TikiLib::lib('tiki'); $paymentlib = TikiLib::lib('payment'); $total = $this->get_total(); if ($total > 0 || $this->total_no_discount) { // if anonymous shopping to set pref as to which shopperinfo to show in description if (empty($user) && $prefs['payment_cart_anonymous'] === 'y') { $shopperinfo_descvar = 'email'; // TODO: make this a pref if (!empty($_SESSION['shopperinfo'][$shopperinfo_descvar])) { $shopperinfo_desc = $_SESSION['shopperinfo'][$shopperinfo_descvar]; $description = tra($prefs['payment_cart_heading']) . " ({$shopperinfo_desc})"; } else { $description = tra($prefs['payment_cart_heading']); } } else { $description = tra($prefs['payment_cart_heading']) . " ({$user})"; } $invoice = $paymentlib->request_payment($description, $total, $prefs['payment_default_delay'], $this->get_description()); foreach ($this->get_behaviors() as $behavior) { $paymentlib->register_behavior($invoice, $behavior['event'], $behavior['behavior'], $behavior['arguments']); } } else { $invoice = 0; foreach ($this->get_behaviors() as $behavior) { if ($behavior['event'] == 'complete') { $name = $behavior['behavior']; $file = dirname(__FILE__) . "/behavior/{$name}.php"; $function = 'payment_behavior_' . $name; require_once $file; call_user_func_array($function, $behavior['arguments']); } } } // Handle anonymous user (not logged in) shopping that require only email if (!$user || isset($_SESSION['forceanon']) && $_SESSION['forceanon'] == 'y') { if (!empty($_SESSION['shopperinfo'])) { // should also check for pref that this anonymous shopping feature is on // First create shopper info in shopper tracker global $record_profile_items_created; $record_profile_items_created = array(); if (!empty($_SESSION['shopperinfoprofile'])) { $shopper_profile_name = $_SESSION['shopperinfoprofile']; } else { $shopper_profile_name = $prefs['payment_cart_anonshopper_profile']; } $shopperprofile = Tiki_Profile::fromDb($shopper_profile_name); $profileinstaller = new Tiki_Profile_Installer(); $profileinstaller->forget($shopperprofile); // profile can be installed multiple times $profileinstaller->setUserData($_SESSION['shopperinfo']); $profileinstaller->install($shopperprofile); // Then set user to shopper ID $cartuser = $record_profile_items_created[0]; $record_profile_items_created = array(); } else { $this->empty_cart(); return $invoice; } } else { $cartuser = $user; } $userInput = array('user' => $cartuser, 'time' => $tikilib->now, 'total' => $total, 'invoice' => $invoice, 'weight' => $this->get_total_weight()); if (!$user || isset($_SESSION['forceanon']) && $_SESSION['forceanon'] == 'y') { $orderprofile = Tiki_Profile::fromDb($prefs['payment_cart_anonorders_profile']); $orderitemprofile = Tiki_Profile::fromDb($prefs['payment_cart_anonorderitems_profile']); } else { $orderprofile = Tiki_Profile::fromDb($prefs['payment_cart_orders_profile']); $orderitemprofile = Tiki_Profile::fromDb($prefs['payment_cart_orderitems_profile']); } if ($user && $prefs['payment_cart_orders'] == 'y' || !$user && $prefs['payment_cart_anonymous'] == 'y') { if (!$orderprofile) { TikiLib::lib('errorreport')->report(tra('Advanced Shopping Cart setup error: Orders profile missing.')); return false; } $profileinstaller = new Tiki_Profile_Installer(); $profileinstaller->forget($orderprofile); // profile can be installed multiple times $profileinstaller->setUserData($userInput); } else { $profileinstaller = ''; } global $record_profile_items_created; $record_profile_items_created = array(); if ($user && $prefs['payment_cart_orders'] == 'y' || !$user && $prefs['payment_cart_anonymous'] == 'y') { $profileinstaller->install($orderprofile, 'none'); } $content = $this->get_content(); foreach ($content as $info) { if (!isset($info['is_gift_certificate']) || !$info['is_gift_certificate']) { $process_info = $this->process_item($invoice, $total, $info, $userInput, $cartuser, $profileinstaller, $orderitemprofile); } } $email_template_ids = array(); if (isset($process_info['product_classes']) && is_array($process_info['product_classes'])) { $product_classes = array_unique($process_info['product_classes']); } else { $product_classes = array(); } foreach ($product_classes as $pc) { if ($email_template_id = $this->get_tracker_value_custom($prefs['payment_cart_productclasses_tracker_name'], 'Email Template ID', $pc)) { $email_template_ids[] = $email_template_id; } } if (!empty($record_profile_items_created)) { if ($total > 0) { $paymentlib->register_behavior($invoice, 'complete', 'record_cart_order', array($record_profile_items_created)); $paymentlib->register_behavior($invoice, 'cancel', 'cancel_cart_order', array($record_profile_items_created)); if ($user) { $paymentlib->register_behavior($invoice, 'complete', 'cart_send_confirm_email', array($user, $email_template_ids)); } } else { require_once 'lib/payment/behavior/record_cart_order.php'; payment_behavior_record_cart_order($record_profile_items_created); if ($user) { require_once 'lib/payment/behavior/cart_send_confirm_email.php'; payment_behavior_cart_send_confirm_email($user, $email_template_ids); } } } if (!$user || isset($_SESSION['forceanon']) && $_SESSION['forceanon'] == 'y') { $shopperurl = 'tiki-index.php?page=' . $prefs['payment_cart_anon_reviewpage'] . '&shopper=' . intval($cartuser); global $tikiroot, $prefs; $shopperurl = $tikilib->httpPrefix(true) . $tikiroot . $shopperurl; require_once 'lib/auth/tokens.php'; $tokenlib = AuthTokens::build($prefs); $shopperurl = $tokenlib->includeToken($shopperurl, array($prefs['payment_cart_anon_group'], 'Anonymous')); if (!empty($_SESSION['shopperinfo']['email'])) { require_once 'lib/webmail/tikimaillib.php'; $smarty = TikiLib::lib('smarty'); $smarty->assign('shopperurl', $shopperurl); $smarty->assign('email_template_ids', $email_template_ids); $mail_subject = $smarty->fetch('mail/cart_order_received_anon_subject.tpl'); $mail_data = $smarty->fetch('mail/cart_order_received_anon.tpl'); $mail = new TikiMail(); $mail->setSubject($mail_subject); if ($mail_data == strip_tags($mail_data)) { $mail->setText($mail_data); } else { $mail->setHtml($mail_data); } $mail->send($_SESSION['shopperinfo']['email']); // the field to use probably needs to be configurable as well } } $this->update_gift_certificate($invoice); $this->update_group_discount($invoice); $this->empty_cart(); return $invoice; }
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()); }
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'; $confirm = $input->getOption('confirm'); $uninstallInfo = json_decode(file_get_contents(TIKI_PATH . '/addons/' . $folder . '/uninstall.json')); $removeItems = $uninstallInfo->remove; $willRemove = false; foreach ($removeItems as $remove) { if (empty($remove->profile)) { $profile = ''; } else { $profile = $remove->profile; } if (empty($remove->domain)) { $domain = ''; } else { $domain = $remove->domain; } $objectId = $addon_utilities->getObjectId($folder, $remove->ref, $profile, $domain); if (is_array($objectId)) { $objectIds = $objectId; } else { $objectIds = [$objectId]; } foreach ($objectIds as $objectId) { $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; } } } $installedProfiles = $addon_utilities->getInstalledProfiles($folder); if (!$confirm && ($willRemove || !empty($installedProfiles))) { $output->writeln("<error>There will be NO undo, and all data in the above objects will be deleted.</error>"); $output->writeln("<info>Use the --confirm option to proceed with removal.</info>"); } elseif (!$willRemove) { $output->writeln("<info>It looks like the objects for this addon have been removed already.</info>"); } if (empty($installedProfiles)) { $output->writeln("<info>It looks like the profiles for this addon have been removed from addon registry already.</info>"); } $tikilib = \TikiLib::lib('tiki'); $installer = new \Tiki_Profile_Installer(); if ($confirm) { foreach (array_keys($installedProfiles) as $profileName) { $profile = \Tiki_Profile::fromNames($repository, $profileName); if (!$profile) { $output->writeln("<error>Profile {$profileName} not found.</error>"); continue; } $isInstalled = $installer->isInstalled($profile); if ($isInstalled) { $transaction = $tikilib->begin(); $installer->forget($profile); $transaction->commit(); $output->writeln("Profile {$profileName} forgotten."); } else { $output->writeln("<info>Profile {$profileName} was not installed or did not create any objects.</info>"); } $addon_utilities->forgetProfileAllVersions($folder, $profileName); $output->writeln("Profile {$profileName} forgotten from addon registry."); } } }
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; } }