/** * delete a contact from user's list * @author: Albert Pérez Monfort (aperezm@xtec.cat) * @param: fuid identity of the user to delete * @return: true if success and false otherwise */ public function deleteContant($args) { // Security check if (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_READ)) { throw new Zikula_Exception_Forbidden(); } $pntables = DBUtil::getTables(); $c = $pntables['IWusers_friends_column']; $where = "WHERE $c[uid]=" . UserUtil::getVar('uid') . " AND $c[fuid]=" . $args['fuid']; if (!DBUtil::deleteObject(array(), 'IWusers_friends', $where)) { return LogUtil::registerError($this->__('Error! Sorry! Deletion attempt failed.')); } return true; }
public function deleteTranslation($args) { $contentId = (int) $args['contentId']; $language = isset($args['language']) ? $args['language'] : null; $includeHistory = isset($args['includeHistory']) ? $args['includeHistory'] : true; $translatedData = array('contentId' => $contentId); if ($language !== null) { $translatedData['language'] = $language; } DBUtil::deleteObject($translatedData, 'content_translatedcontent', '', 'contentId'); $searchableLanguage = $language !== null ? $language : ZLanguage::getLanguageCode(); $dbtables = DBUtil::getTables(); $contentSearchColumn = $dbtables['content_searchable_column']; $where = $contentSearchColumn['contentId'] . ' = ' . $contentId . ' AND ' . $contentSearchColumn['language'] . ' = \'' . DataUtil::formatForStore($searchableLanguage) . '\''; DBUtil::deleteWhere('content_searchable', $where); // Get content to find page ID if ($includeHistory) { $content = $this->getContent(array('id' => $contentId)); if ($content === false) { return false; } $ok = ModUtil::apiFunc('Content', 'History', 'addPageVersion', array('pageId' => $content['pageId'], 'action' => '_CONTENT_HISTORYTRANSLATIONDEL')); if ($ok === false) { return false; } } Content_Util::clearCache(); return true; }
/** * Delete a meta data object. * * @param array &$obj The object we wish to delete metadata for. * @param string $tablename The object's tablename. * @param string $idcolumn The object's idcolumn (optional) (default='id'). * * @return The result from the metadata insert operation */ public static function deleteObjectMetaData(&$obj, $tablename, $idcolumn = 'id') { self::fixObjectMetaData($obj, $tablename, $idcolumn); if (isset($obj['__META__']['id']) && $obj['__META__']['id']) { $rc = DBUtil::deleteObjectByID($obj['__META__'], 'objectdata_meta'); } elseif (isset($obj['__META__']['idcolumn']) && $obj['__META__']['obj_id']) { $dbtables = DBUtil::getTables(); $meta_column = $dbtables['objectdata_meta_column']; $meta = $obj['__META__']; $where = "WHERE {$meta_column['module']}='" . DataUtil::formatForStore($meta['module']) . "'\n AND {$meta_column['table']}='" . DataUtil::formatForStore($meta['table']) . "'\n AND {$meta_column['idcolumn']}='" . DataUtil::formatForStore($meta['idcolumn']) . "'\n AND {$meta_column['obj_id']}='" . DataUtil::formatForStore($meta['obj_id']) . "'"; $rc = DBUtil::deleteObject(array(), 'objectdata_meta', $where); } $dbtables = DBUtil::getTables(); if (isset($dbtables[$tablename])) { DBUtil::flushCache($tablename); } return (bool) $rc; }
/** * Delete one or more user account records, or mark one or more account records for deletion. * * If records are marked for deletion, they remain in the system and accessible by the system, but are given an * 'activated' status that prevents the user from logging in. Records marked for deletion will not appear on the * regular users list. The delete hook and delete events are not triggered if the records are only marked for * deletion. * * Parameters passed in the $args array: * ------------------------------------- * numeric|array $args['uid'] A single (numeric integer) user id, or an array of user ids to delete. * boolean $args['mark'] If true, then mark for deletion, but do not actually delete. * defaults to false. * * @param array $args All parameters passed to this function. * * @return bool True if successful, false otherwise. */ public function deleteUser($args) { if (!SecurityUtil::checkPermission("{$this->name}::", 'ANY', ACCESS_DELETE)) { return false; } if (!isset($args['uid']) || (!is_numeric($args['uid']) && !is_array($args['uid']))) { $this->registerError("Error! Illegal argument were passed to 'deleteuser'"); return false; } if (isset($args['mark']) && is_bool($args['mark'])) { $markOnly = $args['mark']; } else { $markOnly = false; } // ensure we always have an array if (!is_array($args['uid'])) { $args['uid'] = array($args['uid']); } $curUserUid = UserUtil::getVar('uid'); $userList = array(); foreach ($args['uid'] as $uid) { if (!is_numeric($uid) || ((int)$uid != $uid) || ($uid == $curUserUid)) { return false; } $userObj = UserUtil::getVars($uid); if (!$userObj) { return false; } elseif (!SecurityUtil::checkPermission("{$this->name}::", "{$userObj['uname']}::{$userObj['uid']}", ACCESS_DELETE)) { return false; } $userList[] = $userObj; } foreach ($userList as $userObj) { if ($markOnly) { UserUtil::setVar('activated', Users_Constant::ACTIVATED_PENDING_DELETE, $userObj['uid']); } else { // TODO - This should be in the Groups module, and happen as a result of an event. if (!DBUtil::deleteObjectByID('group_membership', $userObj['uid'], 'uid')) { return false; } ModUtil::apiFunc($this->name, 'admin', 'resetVerifyChgFor', array('uid' => $userObj['uid'])); DBUtil::deleteObjectByID('session_info', $userObj['uid'], 'uid'); if (!DBUtil::deleteObject($userObj, 'users', '', 'uid')) { return false; } // Let other modules know we have deleted an item $deleteEvent = new Zikula_Event('user.account.delete', $userObj); $this->eventManager->notify($deleteEvent); } } return $args['uid']; }
/** * Upgrade a module. * * @param array $args All parameters passed to this function. * numeric $args['id'] The module ID. * boolean $args['interactive_upgrade'] Whether or not to upgrade in interactive mode. * * @return boolean True on success, false on failure. */ public function upgrade($args) { // Argument check if (!isset($args['id']) || !is_numeric($args['id'])) { return LogUtil::registerArgsError(); } // Get module information $modinfo = ModUtil::getInfo($args['id']); if (empty($modinfo)) { return LogUtil::registerError($this->__('Error! No such module ID exists.')); } switch ($modinfo['state']) { case ModUtil::STATE_NOTALLOWED: return LogUtil::registerError($this->__f('Error! No permission to upgrade %s.', $modinfo['name'])); break; default: if ($modinfo['state'] > 10) { return LogUtil::registerError($this->__f('Error! %s is not compatible with this version of Zikula.', $modinfo['name'])); } } $osdir = DataUtil::formatForOS($modinfo['directory']); ModUtil::dbInfoLoad($modinfo['name'], $osdir); $modpath = $modinfo['type'] == ModUtil::TYPE_SYSTEM ? 'system' : 'modules'; // load module maintainence functions $oomod = ModUtil::isOO($modinfo['name']); if ($oomod) { ZLoader::addAutoloader($osdir, "{$modpath}/{$osdir}/lib"); } $bootstrap = "{$modpath}/{$osdir}/bootstrap.php"; if (file_exists($bootstrap)) { include_once $bootstrap; } if ($modinfo['type'] == ModUtil::TYPE_MODULE) { if (is_dir("modules/{$osdir}/locale")) { ZLanguage::bindModuleDomain($modinfo['name']); } } if (!$oomod && file_exists($file = "{$modpath}/{$osdir}/pninit.php")) { if (!(include_once $file)) { LogUtil::registerError($this->__f("Error! Could not load a required file: '%s'.", $file)); } } if ($oomod) { $className = ucwords($modinfo['name']) . '_Installer'; $reflectionInstaller = new ReflectionClass($className); if (!$reflectionInstaller->isSubclassOf('Zikula_AbstractInstaller')) { LogUtil::registerError($this->__f("%s must be an instance of Zikula_AbstractInstaller", $className)); } $installer = $reflectionInstaller->newInstanceArgs(array($this->serviceManager)); $interactiveClass = ucwords($modinfo['name']) . '_Controller_Interactiveinstaller'; $interactiveController = null; if (class_exists($interactiveClass)) { $reflectionInteractive = new ReflectionClass($interactiveClass); if (!$reflectionInteractive->isSubclassOf('Zikula_Controller_AbstractInteractiveInstaller')) { LogUtil::registerError($this->__f("%s must be an instance of Zikula_Controller_AbstractInteractiveInstaller", $className)); } $interactiveController = $reflectionInteractive->newInstance($this->serviceManager); } } // perform the actual upgrade of the module $func = $oomod ? array($installer, 'upgrade') : $modinfo['name'] . '_upgrade'; $interactive_func = $oomod ? array($interactiveController, 'upgrade') : $modinfo['name'] . '_init_interactiveupgrade'; // allow bypass of interactive upgrade during a new installation only. if (System::isInstalling() && is_callable($interactive_func) && !is_callable($func)) { return; // return void here } if (isset($args['interactive_upgrade']) && $args['interactive_upgrade'] == false && is_callable($interactive_func)) { if (is_array($interactive_func)) { // This must be an OO controller since callable is an array. // Because interactive installers extend the Zikula_AbstractController, is_callable will always return true because of the __call() // so we must check if the method actually exists by reflection - drak if ($reflectionInteractive->hasMethod('upgrade')) { SessionUtil::setVar('interactive_upgrade', true); return call_user_func($interactive_func, array('oldversion' => $modinfo['version'])); } } else { // this is enclosed in the else so that if both conditions fail, execution will pass onto the non-interactive execution below. SessionUtil::setVar('interactive_upgrade', true); return call_user_func($interactive_func, array('oldversion' => $modinfo['version'])); } } // non-interactive if (is_callable($func)) { $result = call_user_func($func, $modinfo['version']); if (is_string($result)) { if ($result != $modinfo['version']) { // update the last successful updated version $modinfo['version'] = $result; $obj = DBUtil::updateObject($modinfo, 'modules', '', 'id', true); } return false; } elseif ($result != true) { return false; } } $modversion['version'] = '0'; $modversion = Extensions_Util::getVersionMeta($osdir, $modpath); $version = $modversion['version']; // Update state of module $result = $this->setState(array('id' => $args['id'], 'state' => ModUtil::STATE_ACTIVE)); if ($result) { LogUtil::registerStatus($this->__("Done! Module has been upgraded. Its status is now 'Active'.")); } else { return false; } // Note the changes in the database... // Get module database info ModUtil::dbInfoLoad('Extensions'); $obj = array('id' => $args['id'], 'version' => $version); DBUtil::updateObject($obj, 'modules'); // legacy to be removed from 1.4 - remove hooks during upgrade since we cannot rely on // module authors to do this - drak if ($oomod) { $tables = DBUtil::getTables(); $hooksCol = $tables['hooks_column']; $where = "{$hooksCol['smodule']} = '{$modinfo['name']}' OR {$hooksCol['tmodule']} = '{$modinfo['name']}'"; $hooks = DBUtil::selectObjectArray('hooks', $where); if ($hooks) { foreach ($hooks as $hook) { DBUtil::deleteObject($hook, 'hooks'); } LogUtil::registerStatus($this->__f("NOTICE! Legacy hook configurations for %s have been removed.", $modinfo['name'])); } } // Upgrade succeeded, issue event. $event = new Zikula_Event('installer.module.upgraded', null, $modinfo); $this->eventManager->notify($event); // Success return true; }
/** * Creates, saves and sends a registration e-mail address verification code. * * Parameters passed in the $args array: * ------------------------------------- * array $args['reginfo'] An array containing a valid registration record; optional; if not set, then $args['uid'] must * be set and point to a valid registration record. * numeric $args['uid'] The uid of a valid registration record; optional; if not set, then $args['reginfo'] must be set and valid. * boolean $args['force'] Indicates that a verification code should be sent, even if the Users module configuration is * set not to verify e-mail addresses; optional; only has an effect if the current user is * an administrator. * array $args['rendererArgs'] Optional arguments to send to the Zikula_View instance while rendering the e-mail message. * * @param array $args All parameters passed to this function. * * @return bool True on success; otherwise false. * * @throws Zikula_Exception_Forbidden Thrown if the user is not logged in and does not have read access, or if the user is logged in * and does not have moderate access. */ public function sendVerificationCode($args) { // In the future, it is possible we will add a feature to allow a newly registered user to resend // a new verification code to himself after doing a login-like process with information from his // registration record, so allow not-logged-in plus READ, as well as moderator. if ((!UserUtil::isLoggedIn() && !SecurityUtil::checkPermission('Users::', '::', ACCESS_READ)) || (UserUtil::isLoggedIn() && !SecurityUtil::checkPermission('Users::', '::', ACCESS_MODERATE))) { throw new Zikula_Exception_Forbidden(); } if (isset($args['reginfo'])) { // Got a full reginfo record if (!is_array($args['reginfo'])) { $this->registerError(LogUtil::getErrorMsgArgs()); return false; } $reginfo = $args['reginfo']; if (!$reginfo || !is_array($reginfo) || !isset($reginfo['uid']) || !is_numeric($reginfo['uid'])) { $this->registerError(LogUtil::getErrorMsgArgs()); return false; } } elseif (!isset($args['uid']) || !is_numeric($args['uid']) || ((int)$args['uid'] != $args['uid'])) { $this->registerError(LogUtil::getErrorMsgArgs()); return false; } else { // Got just a uid. $reginfo = UserUtil::getVars($args['uid'], false, 'uid', true); if (!$reginfo || empty($reginfo)) { $this->registerError($this->__f('Error! Unable to retrieve registration record with uid \'%1$s\'', $uid)); return false; } if (!isset($reginfo['email'])) { $this->registerError($this->__f('Error! The registration record with uid \'%1$s\' does not contain an e-mail address.', $uid)); return false; } } if ($this->currentUserIsAdmin() && isset($args['force']) && $args['force']) { $forceVerification = true; } else { $forceVerification = false; } if (isset($args['rendererArgs']) && is_array($args['rendererArgs'])) { $rendererArgs = $args['rendererArgs']; } else { $rendererArgs = array(); } $approvalOrder = $this->getVar('moderation_order', Users_Constant::APPROVAL_BEFORE); // Set the verification code if (isset($reginfo['isverified']) && $reginfo['isverified']) { $this->registerError($this->__f('Error! A verification code cannot be sent for the registration record for \'%1$s\'. It is already verified.', $reginfo['uname'])); return false; } elseif (!$forceVerification && ($approvalOrder == Users_Constant::APPROVAL_BEFORE) && isset($reginfo['approvedby']) && !empty($reginfo['approved_by'])) { $this->registerError($this->__f('Error! A verification code cannot be sent for the registration record for \'%1$s\'. It must first be approved.', $reginfo['uname'])); return false; } $nowUTC = new DateTime(null, new DateTimeZone('UTC')); $verificationCode = UserUtil::generatePassword(); ModUtil::apiFunc($this->name, 'user', 'resetVerifyChgFor', array( 'uid' => $reginfo['uid'], 'changetype'=> Users_Constant::VERIFYCHGTYPE_REGEMAIL, )); $verifyChgObj = array( 'changetype'=> Users_Constant::VERIFYCHGTYPE_REGEMAIL, 'uid' => $reginfo['uid'], 'newemail' => $reginfo['email'], 'verifycode'=> UserUtil::getHashedPassword($verificationCode), 'created_dt'=> $nowUTC->format(Users_Constant::DATETIME_FORMAT), ); $verifyChgObj = DBUtil::insertObject($verifyChgObj, 'users_verifychg'); if (!$verifyChgObj) { $this->registerError($this->__f('Error! Unable to save the verification code for the registration for \'%1$s\'.', $reginfo['uname'])); return false; } if (empty($rendererArgs)) { $siteurl = System::getBaseUrl(); $rendererArgs = array(); $rendererArgs['sitename'] = System::getVar('sitename'); $rendererArgs['siteurl'] = substr($siteurl, 0, strlen($siteurl)-1); } $rendererArgs['reginfo'] = $reginfo; $rendererArgs['verifycode'] = $verificationCode; $rendererArgs['approvalorder'] = $approvalOrder; $codeSent = ModUtil::apiFunc($this->name, 'user', 'sendNotification', array( 'toAddress' => $reginfo['email'], 'notificationType' => 'regverifyemail', 'templateArgs' => $rendererArgs, )); if ($codeSent) { return $verifyChgObj['created_dt']; } else { DBUtil::deleteObject($verifyChgObj, 'users_verifychg'); return false; } }
/** * Delete the specified message * @author Sara Arjona Téllez (sarjona@xtec.cat) * @param $args['qvmid'] ID of the message * @return bool true on success, false on failure */ public function deletemessage($args) { // Security check if (!SecurityUtil::checkPermission('IWqv::', '::', ACCESS_ADD)) { return LogUtil::registerError($this->__('Sorry! No authorization to access this module.')); } // Argument check if (!isset($args['qvmid']) || !is_numeric($args['qvmid'])) { return LogUtil::registerError($this->__('Error! Could not do what you wanted. Please check your input.')); } $item = ModUtil::apiFunc('IWqv', 'user', 'getmessage', array('qvmid' => $args[qvmid])); if ($item == false) { return LogUtil::registerError($this->__('No such item found.')); } // Delete the message and the read messages mark $pntable = DBUtil::getTables(); $c = $pntable['IWqv_messages_read_column']; $where = " $c[qvmid]=$args[qvmid] "; if (!DBUtil::deleteObject(array(), 'IWqv_messages_read', $where)) { return LogUtil::registerError($this->__('Error! Sorry! Deletion attempt failed.')); } if (!DBUtil::deleteObjectByID('IWqv_messages', $args['qvmid'], 'qvmid')) { return LogUtil::registerError($this->__('Error! Sorry! Deletion attempt failed.')); } // Let the calling process know that we have finished successfully return true; }
public function deleteTranslation($args) { $contentId = (int) $args['contentId']; $language = isset($args['language']) ? $args['language'] : null; $includeHistory = isset($args['includeHistory']) ? $args['includeHistory'] : true; $translatedData = array('contentId' => $contentId); if ($language != null) { $translatedData['language'] = $language; } DBUtil::deleteObject($translatedData, 'content_translatedcontent', '', 'contentId'); // Get content to find page ID if ($includeHistory) { $content = $this->getContent(array('id' => $contentId)); if ($content === false) { return false; } $ok = ModUtil::apiFunc('Content', 'History', 'addPageVersion', array('pageId' => $content['pageId'], 'action' => '_CONTENT_HISTORYTRANSLATIONDEL' /* delayed translation */)); if ($ok === false) { return false; } } Content_Util::clearCache(); return true; }