Ejemplo n.º 1
0
 public function build($runData)
 {
     // just get some numbers
     $db = Database::connection();
     $q = "SELECT count(*) AS c FROM ozone_user";
     $res = $db->query($q);
     $row = $res->nextRow();
     $totalUsers = $row['c'];
     /* -2 because there are 2 "ghost users" in the default installation 
     			with user_id < 0 */
     $runData->contextAdd("totalUsers", $totalUsers - 2);
     $q = "SELECT count(*) AS c FROM site";
     $res = $db->query($q);
     $row = $res->nextRow();
     $totalSites = $row['c'];
     $runData->contextAdd("totalSites", $totalSites);
     $q = "SELECT count(*) AS c FROM page";
     $res = $db->query($q);
     $row = $res->nextRow();
     $totalPages = $row['c'];
     $runData->contextAdd("totalPages", $totalPages);
     $q = "SELECT count(*) AS c FROM ozone_user WHERE registered_date>now() - interval '1 day'";
     $res = $db->query($q);
     $row = $res->nextRow();
     $newUsers = $row['c'];
     $runData->contextAdd("newUsers", $newUsers);
     $q = "SELECT count(*) AS c FROM page_revision WHERE date_last_edited>now() - interval '1 day'";
     $res = $db->query($q);
     $row = $res->nextRow();
     $recentEdits = $row['c'];
     $runData->contextAdd("recentEdits", $recentEdits);
 }
Ejemplo n.º 2
0
 public function process($data)
 {
     // does not use data
     $search = $_GET['q'];
     if ($search == null || strlen($search) == 0) {
         return;
     }
     $search1 = pg_escape_string(preg_quote($search));
     $search2 = pg_escape_string($search);
     Database::init();
     $q1 = "SELECT nick_name AS name, user_id FROM ozone_user WHERE " . "nick_name ~* '^{$search1}' AND nick_name != '{$search2}'";
     $q1 .= "ORDER BY nick_name LIMIT 20";
     $q2 = "SELECT nick_name AS name, user_id FROM ozone_user WHERE " . "nick_name = '{$search2}' ";
     $db = Database::connection();
     $result1 = $db->query($q1);
     $result1 = $result1->fetchAll();
     $result2 = $db->query($q2);
     $result2 = $result2->fetchAll();
     if ($result1 == null && $result2 != null) {
         $result = $result2;
     }
     if ($result2 == null && $result1 != null) {
         $result = $result1;
     }
     if ($result1 == null && $result2 == null) {
         $result = false;
     }
     // NOT null since it breakes autocomplete!!!
     if ($result1 != null && $result2 != null) {
         $result = array_merge($result2, $result1);
     }
     return array('users' => $result);
 }
Ejemplo n.º 3
0
 public function build($runData)
 {
     $site = $runData->getTemp("site");
     // get
     $q = "SELECT target_user_id, count(*) AS rank " . "FROM user_abuse_flag " . "WHERE site_id='" . $site->getSiteId() . "' " . "AND site_valid = TRUE GROUP BY target_user_id ORDER BY rank DESC, target_user_id";
     $db = Database::connection();
     $res = $db->query($q);
     $all = $res->fetchAll();
     $r2 = array();
     if ($all) {
         foreach ($all as &$r) {
             // get user
             $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($r['target_user_id']);
             if ($user) {
                 $r['user'] = $user;
                 // check if member
                 $c = new Criteria();
                 $c->add("site_id", $site->getSiteId());
                 $c->add("user_id", $user->getUserId());
                 $mem = DB_MemberPeer::instance()->selectOne($c);
                 if ($mem) {
                     $r['member'] = $mem;
                 }
                 $r2[] = $r;
             }
         }
     }
     $runData->contextAdd("reps", $r2);
 }
 public function import(\SimpleXMLElement $sx)
 {
     $em = \Database::connection()->getEntityManager();
     $em->getClassMetadata('Concrete\\Core\\Entity\\Express\\Entity')->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
     if (isset($sx->expressentities)) {
         foreach ($sx->expressentities->entity as $entityNode) {
             $entity = $em->find('Concrete\\Core\\Entity\\Express\\Entity', (string) $entityNode['id']);
             if (!is_object($entity)) {
                 $entity = new Entity();
                 $entity->setId((string) $entityNode['id']);
             }
             $entity->setPluralHandle((string) $entityNode['plural_handle']);
             $entity->setHandle((string) $entityNode['handle']);
             $entity->setDescription((string) $entityNode['description']);
             $entity->setName((string) $entityNode['name']);
             if ((string) $entityNode['include_in_public_list'] == '') {
                 $entity->setIncludeInPublicList(false);
             }
             $entity->setHandle((string) $entityNode['handle']);
             $tree = ExpressEntryResults::get();
             $node = $tree->getNodeByDisplayPath((string) $entityNode['results-folder']);
             $node = \Concrete\Core\Tree\Node\Type\ExpressEntryResults::add((string) $entityNode['name'], $node);
             $entity->setEntityResultsNodeId($node->getTreeNodeID());
             $indexer = $entity->getAttributeKeyCategory()->getSearchIndexer();
             if (is_object($indexer)) {
                 $indexer->createRepository($entity->getAttributeKeyCategory());
             }
             $em->persist($entity);
         }
     }
     $em->flush();
     $em->getClassMetadata('Concrete\\Core\\Entity\\Express\\Entity')->setIdGenerator(new UuidGenerator());
 }
Ejemplo n.º 5
0
 private static function getConnection()
 {
     if (self::$connection == null) {
         self::$connection = mysqli_connect("localhost", "root", "", "postthelink_base");
     }
     return self::$connection;
 }
Ejemplo n.º 6
0
 private static function CreateConnection()
 {
     self::$connection = new \PDO('mysql:host=' . self::$dsn . ';dbname=' . self::$database . ';', self::$username, self::$password, array(\PDO::FETCH_OBJ));
     self::$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     self::$connection->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
     return self::$connection;
 }
Ejemplo n.º 7
0
 public function run()
 {
     // check!
     $c = new Criteria();
     $c->add("status", null);
     $c->addOrderDescending("backup_id");
     $sb = DB_SiteBackupPeer::instance()->selectOne($c);
     // select only one!
     if (!$sb) {
         return;
     }
     $db = Database::connection();
     $sb->setStatus("started");
     $sb->save();
     $db->begin();
     try {
         $b = new Backuper();
         $b->setConfig($sb);
         $b->backup();
         // check
         $sb->setStatus("completed");
         $sb->setDate(new ODate());
         $sb->setRand($b->getRand());
         $sb->save();
     } catch (Exception $e) {
         $sb->setStatus("failed");
         $sb->save();
     }
     $db->commit();
 }
Ejemplo n.º 8
0
 public static function connect()
 {
     if (!isset(self::$connection)) {
         self::$connection = new Database();
     }
     return self::$pdo;
 }
 public static function getInstance()
 {
     if (is_null(self::$connection)) {
         self::$connection = new Database();
     }
     return self::$connection;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $db = \Database::connection();
     $em = $db->getEntityManager();
     $cacheDriver = $em->getConfiguration()->getMetadataCacheImpl();
     $cacheDriver->flushAll();
     $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $schemas = [];
     /**
      * @var $sm MySqlSchemaManager
      */
     $sm = $db->getSchemaManager();
     $dbSchema = $sm->createSchema();
     // core xml tables
     $schemas[] = Schema::getCoreXMLSchema();
     // core entities
     $sm = new DatabaseStructureManager($em);
     $entities = $sm->getMetadatas();
     $schemas[] = $tool->getSchemaFromMetadata($entities);
     // core, application and package block types
     $env = Environment::get();
     $list = new BlockTypeList();
     $list->includeInternalBlockTypes();
     foreach ($list->get() as $bt) {
         $r = $env->getRecord(DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . '/' . FILENAME_BLOCK_DB, $bt->getPackageHandle());
         if ($r->exists()) {
             $parser = Schema::getSchemaParser(simplexml_load_file($r->file));
             $parser->setIgnoreExistingTables(false);
             $schemas[] = $parser->parse($db);
         }
     }
     // packages
     $packages = Package::getInstalledList();
     foreach ($packages as $pkg) {
         $xmlFile = $pkg->getPackagePath() . '/' . FILENAME_BLOCK_DB;
         if (file_exists($xmlFile)) {
             $parser = Schema::getSchemaParser(simplexml_load_file($xmlFile));
             $parser->setIgnoreExistingTables(false);
             $schemas[] = $parser->parse($db);
         }
     }
     // Finalize output.
     $comparator = new \Doctrine\DBAL\Schema\Comparator();
     $saveQueries = array();
     foreach ($schemas as $schema) {
         $schemaDiff = $comparator->compare($dbSchema, $schema);
         $saveQueries = array_merge($saveQueries, $schemaDiff->toSaveSql($db->getDatabasePlatform()));
     }
     $saveQueries = $this->filterQueries($saveQueries);
     if (count($saveQueries)) {
         $output->writeln(t2('%s query found', '%s queries found', count($saveQueries)));
         $i = 1;
         foreach ($saveQueries as $query) {
             $output->writeln(sprintf('%s: %s', $i, $query));
             $i++;
         }
     } else {
         $output->writeln(t('No differences found between schema and database.'));
     }
 }
Ejemplo n.º 11
0
 /**
  * @return DatabaseConnection
  * @desc Gets the one and only global database connection
  */
 public static function getDatabase()
 {
     if (empty(self::$connection)) {
         self::$connection = new DatabaseConnection();
     }
     return self::$connection;
 }
 public static function popular()
 {
     $pdo = Database::connection();
     $sql = 'SELECT * FROM produtos ORDER BY quantidadeDeAcessos DESC LIMIT 5';
     $query = $pdo->query($sql);
     return $query->fetchAll(PDO::FETCH_ASSOC);
 }
Ejemplo n.º 13
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $threadId = $pl->getParameterValue("threadId");
     $site = $runData->getTemp("site");
     $user = $runData->getUser();
     $db = Database::connection();
     $db->begin();
     $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($threadId);
     if ($thread == null || $thread->getSiteId() !== $site->getSiteId()) {
         throw new ProcessException(_("No thread found... Is it deleted?"), "no_thread");
     }
     // check if thread blocked
     if ($thread->getBlocked()) {
         // check if moderator or admin
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $c->add("user_id", $user->getUserId());
         $rel = DB_ModeratorPeer::instance()->selectOne($c);
         if (!$rel || strpos($rel->getPermissions(), 'f') == false) {
             $rel = DB_AdminPeer::instance()->selectOne($c);
             if (!$rel) {
                 throw new WDPermissionException(_("Sorry, this thread is blocked. Nobody can add new posts nor edit existing ones."));
             }
         }
     }
     $category = $thread->getCategory();
     WDPermissionManager::instance()->hasForumPermission('edit_thread', $runData->getUser(), $category, $thread);
     $runData->contextAdd("thread", $thread);
     $db->commit();
 }
Ejemplo n.º 14
0
 /**
  * Main db Connection
  */
 public static function connectify()
 {
     if (Database::$connection == null) {
         Database::$connection = new PDO(Database::$driver . ';' . 'Server=' . Database::$host . ';' . 'Database=' . Database::$db . ';', Database::$user, Database::$pass);
     }
     return Database::$connection;
 }
Ejemplo n.º 15
0
 /**
  * Initializes this database class.
  */
 private static function initialize()
 {
     if (self::$connection != null) {
         return;
     }
     self::$connection = self::getConnection();
 }
Ejemplo n.º 16
0
 public function totalSiteFileNumber($siteId)
 {
     $q = "SELECT count(*) AS count FROM file WHERE site_id='" . db_escape_string($siteId) . "'\t";
     $db = Database::connection();
     $r = $db->query($q)->nextRow();
     return $r['count'];
 }
 public function import(\SimpleXMLElement $sx)
 {
     $em = \Database::connection()->getEntityManager();
     $em->getClassMetadata('Concrete\\Core\\Entity\\Express\\Association')->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
     if (isset($sx->expressentities)) {
         foreach ($sx->expressentities->entity as $entityNode) {
             if (isset($entityNode->associations)) {
                 foreach ($entityNode->associations->association as $associationNode) {
                     $association = $em->find('Concrete\\Core\\Entity\\Express\\Association', (string) $associationNode['id']);
                     if (!is_object($association)) {
                         $class = '\\Concrete\\Core\\Entity\\Express\\' . camelcase((string) $associationNode['type']) . 'Association';
                         $association = new $class();
                         $association->setId((string) $associationNode['id']);
                     }
                     /**
                      * @var $association \Concrete\Core\Entity\Express\Association
                      */
                     $association->setTargetPropertyName((string) $associationNode['target-property-name']);
                     $association->setInversedByPropertyName((string) $associationNode['inversed-by-property-name']);
                     $em->persist($association);
                 }
             }
         }
     }
     $em->flush();
     $em->getClassMetadata('Concrete\\Core\\Entity\\Express\\Association')->setIdGenerator(new UuidGenerator());
 }
Ejemplo n.º 18
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $range = $pl->getParameterValue("range", "AMODULE");
     $dateStart = new ODate();
     if (!in_array($range, array('24h', '7days', 'month'))) {
         $range = '7days';
     }
     switch ($range) {
         case '24h':
             $dateStart->addSeconds(-60 * 60 * 24);
             break;
         case '7days':
             $dateStart->addSeconds(-60 * 60 * 24 * 7);
             break;
         case 'month':
             $dateStart->addSeconds(-60 * 60 * 24 * 31);
             break;
     }
     $q = "SELECT site.site_id, count(*) AS number_changes FROM site, page_revision WHERE page_revision.date_last_edited > '" . $dateStart->getDate() . "' AND site.visible = TRUE AND site.private = FALSE AND site.deleted = FALSE AND site.site_id != 1 AND page_revision.flag_new_site=FALSE AND page_revision.site_id = site.site_id GROUP BY site.site_id ORDER BY number_changes DESC LIMIT 10";
     $db = Database::connection();
     $res = $db->query($q);
     $all = $res->fetchAll();
     if ($all) {
         foreach ($all as &$a) {
             $a['site'] = DB_SitePeer::instance()->selectByPrimaryKey($a['site_id']);
         }
     }
     $runData->contextAdd("res", $all);
     $runData->contextAdd("range", $range);
 }
Ejemplo n.º 19
0
 public function Connect()
 {
     self::$connection = mysqli_connect(Config::Get("db.host"), Config::Get("db.username"), Config::Get("db.password"), Config::Get("db.name"));
     if (mysqli_connect_errno()) {
         die("Failed to connect to MySQL");
     }
 }
Ejemplo n.º 20
0
 public function process($data)
 {
     $search = $_GET['q'];
     $siteId = $_GET['s'];
     if (isset($_GET['parent'])) {
         $parent = WDStringUtils::toUnixName($_GET['parent']);
     } else {
         $parent = null;
     }
     $title = isset($_GET['title']) && $_GET['title'] == 'yes';
     if (!is_numeric($siteId) || $search == null || strlen($search) == 0) {
         return;
     }
     $search = pg_escape_string(preg_quote(str_replace(' ', '-', $search)));
     $siteId = pg_escape_string($siteId);
     $orTitle = $title ? "OR title ~* '^{$search}'" : "";
     $query = "SELECT unix_name, COALESCE(title,unix_name) AS title FROM page ";
     $query .= "WHERE site_id ='{$siteId}' AND (unix_name ~* '^{$search}' {$orTitle})";
     if ($parent) {
         $parent = pg_escape_string($parent);
         $query .= " AND parent_page_id IN (SELECT page_id FROM page WHERE unix_name = '{$parent}') ";
     }
     $query .= "ORDER BY unix_name";
     Database::init();
     return array('pages' => Database::connection()->query($query)->fetchAll());
 }
Ejemplo n.º 21
0
 /**
  * Create a new session driver instance.
  *
  * @param  string  $driver
  * @return Session\Drivers\Driver
  */
 public static function factory($driver)
 {
     if (isset(static::$registrar[$driver])) {
         $resolver = static::$registrar[$driver];
         return $resolver();
     }
     switch ($driver) {
         case 'apc':
             return new Session\Drivers\APC(Cache::driver('apc'));
         case 'cookie':
             return new Session\Drivers\Cookie();
         case 'database':
             return new Session\Drivers\Database(Database::connection());
         case 'file':
             return new Session\Drivers\File(path('storage') . 'sessions' . DS);
         case 'memcached':
             return new Session\Drivers\Memcached(Cache::driver('memcached'));
         case 'memory':
             return new Session\Drivers\Memory();
         case 'redis':
             return new Session\Drivers\Redis(Cache::driver('redis'));
         default:
             throw new \Exception("Session driver [{$driver}] is not supported.");
     }
 }
Ejemplo n.º 22
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $threadId = $pl->getParameterValue("threadId");
     $site = $runData->getTemp("site");
     $db = Database::connection();
     $db->begin();
     $thread = DB_ForumThreadPeer::instance()->selectByPrimaryKey($threadId);
     if ($thread == null || $thread->getSiteId() !== $site->getSiteId()) {
         throw new ProcessException(_("No thread found... Is it deleted?"), "no_thread");
     }
     $category = $thread->getForumCategory();
     WDPermissionManager::instance()->hasForumPermission('moderate_forum', $runData->getUser(), $category);
     $runData->contextAdd("thread", $thread);
     $runData->contextAdd("category", $thread->getForumCategory());
     // and select categories to move into too.
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->addOrderDescending("visible");
     $c->addOrderAscending("sort_index");
     $groups = DB_ForumGroupPeer::instance()->select($c);
     $res = array();
     foreach ($groups as $g) {
         $c = new Criteria();
         $c->add("group_id", $g->getGroupId());
         $c->addOrderAscending("sort_index");
         $categories = DB_ForumCategoryPeer::instance()->select($c);
         foreach ($categories as $cat) {
             $res[] = array('group' => $g, 'category' => $cat);
         }
     }
     $runData->contextAdd("categories", $res);
     $db->commit();
 }
Ejemplo n.º 23
0
 public function submit($entityID)
 {
     $em = \Database::connection()->getEntityManager();
     $entity = $em->getRepository('Concrete\\Core\\Entity\\Express\\Entity')->findOneById($entityID);
     $this->search($entity);
     $this->app->make('helper/ajax')->sendResult($this->result->getJSONObject());
 }
Ejemplo n.º 24
0
 public function connection($connection = null)
 {
     if (!empty($this->_config['charset'])) {
         // Set the character set
         $this->set_charset($this->_config['charset']);
     }
     return parent::connection($connection);
 }
Ejemplo n.º 25
0
 public function execute()
 {
     $dbh =& Database::connection();
     $this->result = $dbh->prepare($this->__toString());
     $this->result->execute();
     Database::commit();
     $dbh = null;
 }
Ejemplo n.º 26
0
 /**
  * Opens a new database connection with parameters from config.php
  */
 private static function openConnection()
 {
     self::$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
     if (self::$connection->connect_errno) {
         echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
     }
     return self::$connection;
 }
 public static function delete($id)
 {
     $pdo = Database::connection();
     $sql = 'DELETE FROM produtos WHERE id = ?';
     $query = $pdo->prepare($sql);
     $query->execute(array($id));
     return $query->rowCount() > 0;
 }
 public function getDefaultParentPageID()
 {
     $db = \Database::connection();
     $ids = $db->GetCol('select cID from Pages where ptID = ? and cIsTemplate = 0 and cIsActive = 1', [$this->getPageTypeID()]);
     if (count($ids) == 1) {
         return $ids[0];
     }
 }
Ejemplo n.º 29
0
 public static function getNodeBySavedSearchID($presetID)
 {
     $db = \Database::connection();
     $nodeID = $db->GetOne('select treeNodeID from TreeSearchQueryNodes where savedSearchID = ?', array($presetID));
     if ($nodeID) {
         return static::getByID($nodeID);
     }
 }
Ejemplo n.º 30
0
 public static function connect($host, $login, $password, $database, $charset)
 {
     self::$connection = mysqli_connect($host, $login, $password, $database);
     if (!self::$connection) {
         throw new DatabaseException("Database connection error");
     }
     mysqli_set_charset(self::$connection, $charset);
 }