/** * Deletes this record (no checks) * * @param int $oid Key id of row to delete (otherwise it's the one of $this) (only int supported here) * @return boolean TRUE if OK, FALSE if error */ public function delete($oid = null) { $k = $this->_tbl_key; if ($oid) { $this->{$k} = (int) $oid; } cbimport('cb.installer'); ob_start(); $plgInstaller = new \cbInstallerPlugin(); //TODO: Move $installed = $plgInstaller->uninstall($this->{$k}, 'com_comprofiler'); ob_end_clean(); if (!$installed) { $this->_error = $plgInstaller->getError(); return false; } return true; }
function plug_cbgallery_install() { global $_CB_framework, $_CB_database; $plugin = new PluginTable(); if ( $plugin->load( array( 'element' => 'cb.profilegallery' ) ) ) { $path = $_CB_framework->getCfg( 'absolute_path' ); $indexPath = $path . '/components/com_comprofiler/plugin/user/plug_cbgallery/index.html'; $oldFilesPath = $path . '/images/comprofiler/plug_profilegallery'; $newFilesPath = $path . '/images/comprofiler/plug_cbgallery'; $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plug_profilegallery' ); $_CB_database->setQuery( $query ); $rows = $_CB_database->loadObjectList( null, '\CBLib\Database\Table\Table', array( $_CB_database, '#__comprofiler_plug_profilegallery', 'id' ) ); /** @var $rows Table[] */ foreach ( $rows as $row ) { $oldFilePath = $oldFilesPath . '/' . (int) $row->get( 'userid' ); if ( in_array( $row->get( 'pgitemtype' ), array( 'jpg', 'jpeg', 'gif', 'png' ) ) ) { $type = 'photos'; } else { $type = 'files'; } $newFilePath = $newFilesPath . '/' . (int) $row->get( 'userid' ) . '/' . $type; if ( ( ! file_exists( $oldFilePath . '/' . $row->get( 'pgitemfilename' ) ) ) || ( ( $type == 'photos' ) && ( ! file_exists( $oldFilePath . '/tn' . $row->get( 'pgitemfilename' ) ) ) ) ) { continue; } $cleanFileName = str_replace( 'pg_', '', pathinfo( $row->get( 'pgitemfilename' ), PATHINFO_FILENAME ) ); $newFileName = uniqid( $cleanFileName . '_' ) . '.' . strtolower( pathinfo( $row->get( 'pgitemfilename' ), PATHINFO_EXTENSION ) ); if ( cbReadDirectory( $newFilePath, '^' . preg_quote( $cleanFileName ) ) ) { $query = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_gallery_items' ) . "\n WHERE " . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $row->get( 'userid' ) . "\n AND " . $_CB_database->NameQuote( 'value' ) . " LIKE " . $_CB_database->Quote( '%' . $_CB_database->getEscaped( $cleanFileName, true ) . '%', false ); $_CB_database->setQuery( $query ); if ( $_CB_database->loadResult() ) { continue; } } if ( ! is_dir( $newFilesPath ) ) { $oldMask = @umask( 0 ); if ( @mkdir( $newFilesPath, 0755, true ) ) { @umask( $oldMask ); @chmod( $newFilesPath, 0755 ); if ( ! file_exists( $newFilesPath . '/index.html' ) ) { @copy( $indexPath, $newFilesPath . '/index.html' ); @chmod( $newFilesPath . '/index.html', 0755 ); } } else { @umask( $oldMask ); } } if ( ! file_exists( $newFilesPath . '/.htaccess' ) ) { file_put_contents( $newFilesPath . '/.htaccess', 'deny from all' ); } if ( ! is_dir( $newFilePath ) ) { $oldMask = @umask( 0 ); if ( @mkdir( $newFilePath, 0755, true ) ) { @umask( $oldMask ); @chmod( $newFilePath, 0755 ); if ( ! file_exists( $newFilePath . '/index.html' ) ) { @copy( $indexPath, $newFilePath . '/index.html' ); @chmod( $newFilePath . '/index.html', 0755 ); } } else { @umask( $oldMask ); } } if ( ! @copy( $oldFilePath . '/' . $row->get( 'pgitemfilename' ), $newFilePath . '/' . $newFileName ) ) { continue; } else { @chmod( $newFilePath . '/' . $newFileName, 0755 ); } if ( $type == 'photos' ) { if ( ! @copy( $oldFilePath . '/tn' . $row->get( 'pgitemfilename' ), $newFilePath . '/tn' . $newFileName ) ) { continue; } else { @chmod( $newFilePath . '/tn' . $newFileName, 0755 ); } } $item = new Table( null, '#__comprofiler_plugin_gallery_items', 'id' ); $item->set( 'user_id', (int) $row->get( 'userid' ) ); $item->set( 'type', $type ); $item->set( 'value', $newFileName ); $item->set( 'folder', 0 ); $item->set( 'title', $row->get( 'pgitemtitle' ) ); $item->set( 'description', $row->get( 'pgitemdescription' ) ); $item->set( 'date', $row->get( 'pgitemdate' ) ); $item->set( 'published', ( $row->get( 'pgitemapproved', 0 ) ? (int) $row->get( 'pgitempublished', 0 ) : -1 ) ); if ( ! $item->store() ) { @unlink( $newFilePath . '/' . $newFileName ); if ( $type == 'photos' ) { @unlink( $newFilePath . '/tn' . $newFileName ); } } } $field = new FieldTable(); if ( $field->load( array( 'name' => 'cb_pgtotalquotaitems' ) ) ) { $field->set( 'type', 'integer' ); $field->set( 'tabid', 11 ); $field->set( 'pluginid', 1 ); $field->set( 'readonly', 1 ); $field->set( 'calculated', 0 ); $field->set( 'sys', 0 ); $field->store(); } $gallery = new PluginTable(); if ( $gallery->load( array( 'element' => 'cbgallery' ) ) ) { $galleryParams = new Registry( $gallery->params ); $galleryParams->set( 'photos_item_limit', 'cb_pgtotalquotaitems' ); $galleryParams->set( 'files_item_limit', 'cb_pgtotalquotaitems' ); $gallery->set( 'params', $galleryParams->asJson() ); $gallery->store(); } ob_start(); $plgInstaller = new cbInstallerPlugin(); $plgInstaller->uninstall( $plugin->id, 'com_comprofiler' ); ob_end_clean(); } }
public function migrate() { $step = JRequest::getInt('step'); if (!$step) { echo json_encode(array('error' => "Invalid request (step = {$step})")); exit; } $db = JFactory::getDBO(); $res = array('success' => true); switch ($step) { // migrate plugin configuration case 1: $query = $db->getQuery(true)->select($db->qn(array('params', 'enabled')))->from($db->qn('#__extensions'))->where($db->qn('type') . ' = ' . $db->q('plugin'))->where($db->qn('folder') . ' = ' . $db->q('system'))->where($db->qn('element') . ' = ' . $db->q('joomailermailchimpsignup')); $db->setQuery($query); try { $pluginData = $db->loadObject(); } catch (Exception $e) { $res = array('error' => $e->getMessage(), 'query' => $query); echo json_encode($res); exit; } if (!$pluginData) { $res = array('notRequired' => true); break; } $query = $db->getQuery(true)->update($db->qn('#__extensions'))->set($db->qn('enabled') . ' = ' . $db->q($pluginData->enabled))->set($db->qn('params') . ' = ' . $db->q($pluginData->params))->where($db->qn('type') . ' = ' . $db->q('plugin'))->where($db->qn('folder') . ' = ' . $db->q('user'))->where($db->qn('element') . ' = ' . $db->q('joomlamailer')); $db->setQuery($query); try { $db->execute(); } catch (Exception $e) { $res = array('error' => $e->getMessage(), 'query' => $query); echo json_encode($res); exit; } break; // uninstall system plugin // uninstall system plugin case 2: $query = $db->getQuery(true)->select($db->qn('extension_id'))->from($db->qn('#__extensions'))->where($db->qn('type') . ' = ' . $db->q('plugin'))->where($db->qn('folder') . ' = ' . $db->q('system'))->where($db->qn('element') . ' = ' . $db->q('joomailermailchimpsignup')); $db->setQuery($query); try { $extension_id = $db->loadResult(); } catch (Exception $e) { $res = array('error' => $e->getMessage(), 'query' => $query); echo json_encode($res); exit; } if ($extension_id) { jimport('joomla.installer.installer'); $installer = new JInstaller(); $installer->uninstall('plugin', $extension_id, 0); } else { $res = array('notRequired' => true); } break; // uninstall signup component // uninstall signup component case 3: $query = $db->getQuery(true)->select($db->qn('extension_id'))->from($db->qn('#__extensions'))->where($db->qn('type') . ' = ' . $db->q('component'))->where($db->qn('element') . ' = ' . $db->q('com_joomailermailchimpsignup')); $db->setQuery($query); try { $extension_id = $db->loadResult(); } catch (Exception $e) { $res = array('error' => $e->getMessage(), 'query' => $query); echo json_encode($res); exit; } if ($extension_id) { jimport('joomla.installer.installer'); $installer = new JInstaller(); $installer->uninstall('component', $extension_id, 0); try { $db->dropTable('#__joomailermailchimpsignup'); } catch (Exception $e) { $res = array('error' => $e->getMessage(), 'query' => $query); echo json_encode($res); exit; } } else { $res = array('notRequired' => true); } break; // uninstall community builder plugin // uninstall community builder plugin case 4: if (!JFile::exists(JPATH_ROOT . '/libraries/CBLib/CB/Application/CBApplication.php') || !JFile::exists(JPATH_ROOT . '/libraries/CBLib/CB/Legacy/LegacyComprofilerFunctions.php') || !JFile::exists(JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.class.php')) { $res = array('notRequired' => true); echo json_encode($res); exit; } $query = $db->getQuery(true)->select($db->qn('id'))->from($db->qn('#__comprofiler_plugin'))->where($db->qn('element') . ' = ' . $db->q('cb.joomlamailer'))->where($db->qn('folder') . ' = ' . $db->q('plug_joomlamailercbsignup')); $db->setQuery($query); try { $extension_id = $db->loadResult(); } catch (Exception $e) { $res = array('error' => $e->getMessage(), 'query' => $query); echo json_encode($res); exit; } if ($extension_id) { require_once JPATH_ROOT . '/libraries/CBLib/CB/Application/CBApplication.php'; require_once JPATH_ROOT . '/libraries/CBLib/CB/Legacy/LegacyComprofilerFunctions.php'; CB\Application\CBApplication::init()->getDI()->get('\\CB\\Legacy\\LegacyFoundationFunctions'); require_once JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.class.php'; $cbInstallerPlugin = new cbInstallerPlugin(); $cbInstallerPlugin->uninstall($extension_id, 'com_joomailermailchimpintegration'); } else { $res = array('notRequired' => true); } break; default: echo json_encode(array('error' => "Invalid request (step = {$step})")); exit; } echo json_encode($res); }
/** * Deletes one or more plugins * * Also deletes associated entries in the #__comprofiler_plugin table. * @param array An array of unique category id numbers */ function removePlugin(&$cid, $option) { if (count($cid) < 1) { echo "<script type=\"text/javascript\"> alert('" . addslashes(CBTxt::T('Select a plugin to delete')) . "'); window.history.go(-1);</script>\n"; exit; } $installer = new cbInstallerPlugin(); foreach ($cid as $id) { $ret = $installer->uninstall($id, $option); if (!$ret) { break; } } if ($ret) { HTML_comprofiler::showInstallMessage($installer->getError(), CBTxt::T('Uninstall Plugin') . ' - ' . ($ret ? CBTxt::T('Success') : CBTxt::T('Failed')), $installer->returnTo($option, 'showPlugins')); } }
function cbInstaller_uninstall_plugin($plugin, &$return) { if ($plugin->id) { ob_start(); $plgInstaller = new cbInstallerPlugin(); $installed = $plgInstaller->uninstall($plugin->id, 'com_comprofiler'); ob_end_clean(); if (!$installed) { $return .= '<div style="font-size:14px;color:red;margin-bottom:10px;">' . CBTxt::P('Conflicting plugin [element] failed to uninstall. Error: [error]', array('[element]' => $plugin->element, '[error]' => $plgInstaller->getError())) . '</div>'; return false; } } return true; }