Ejemplo n.º 1
0
    def walk(self):
        """Walks around and returns all objects which needs migration

        :return: objects (with acquisition wrapper) that needs migration
        :rtype: generator
        """
        catalog = self.catalog
        query = self.additionalQuery
        query['portal_type'] = self.src_portal_type
        query['meta_type'] = self.src_meta_type

        if HAS_LINGUA_PLONE and 'Language' in catalog.indexes():
            #query['Language'] = catalog.uniqueValuesFor('Language')
            query['Language'] = 'all'

        results = []
        for addQ in self.additionalQueries:
            addQ.update(query)
            results.append(catalog(addQ))
        brains = mergeResults(results, has_sort_keys=False,
                              reverse=False)

        for brain in brains:
            obj = brain.getObject()

            if self.callBefore is not None and callable(self.callBefore):
                if self.callBefore(obj, **self.kwargs) == False:
                    continue

            try: state = obj._p_changed
            except: state = 0
            if obj is not None:
                yield obj
                # safe my butt
                if state is None: obj._p_deactivate()
Ejemplo n.º 2
0
    def testNoFilterOrSort(self):
        from Products.ZCatalog.Catalog import mergeResults

        results = [cat.searchResults(dict(number=True), _merge=0) for cat in self.catalogs]
        merged_rids = [r.getRID() for r in mergeResults(results, has_sort_keys=False, reverse=False)]
        expected = [r.getRID() for r in chain(*results)]
        self.assertEqual(sort(merged_rids), sort(expected))
Ejemplo n.º 3
0
    def walk(self):
        """Walks around and returns all objects which needs migration

        :return: objects (with acquisition wrapper) that needs migration
        :rtype: generator
        """
        catalog = self.catalog
        query = self.additionalQuery
        query['portal_type'] = self.src_portal_type
        query['meta_type'] = self.src_meta_type

        if HAS_LINGUA_PLONE and 'Language' in catalog.indexes():
            #query['Language'] = catalog.uniqueValuesFor('Language')
            query['Language'] = 'all'

        results = []
        for addQ in self.additionalQueries:
            addQ.update(query)
            results.append(catalog(addQ))
        brains = mergeResults(results, has_sort_keys=False,
                              reverse=False)
            
        for brain in brains:
            obj = brain.getObject()
            
            if self.callBefore is not None and callable(self.callBefore):
                if self.callBefore(obj, **self.kwargs) == False:
                    continue
            
            try: state = obj._p_changed
            except: state = 0
            if obj is not None:
                yield obj
                # safe my butt
                if state is None: obj._p_deactivate()
Ejemplo n.º 4
0
 def testNoFilterOrSort(self):
     from Products.ZCatalog.Catalog import mergeResults
     results = [cat.searchResults(
                dict(number=True), _merge=0) for cat in self.catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=False, reverse=False)]
     expected = [r.getRID() for r in chain(*results)]
     self.assertEqual(sort(merged_rids), sort(expected))
Ejemplo n.º 5
0
    def testScored(self):
        from Products.ZCatalog.Catalog import mergeResults

        results = [cat.searchResults(title="4 or 5 or 6", _merge=0) for cat in self.catalogs]
        merged_rids = [r.getRID() for r in mergeResults(results, has_sort_keys=True, reverse=False)]
        expected = sort(chain(*results))
        expected = [rid for sortkey, (nscore, score, rid), getitem in expected]
        self.assertEqual(merged_rids, expected)
Ejemplo n.º 6
0
    def testSortReverse(self):
        from Products.ZCatalog.Catalog import mergeResults

        results = [cat.searchResults(dict(number=True, sort_on="num"), _merge=0) for cat in self.catalogs]
        merged_rids = [r.getRID() for r in mergeResults(results, has_sort_keys=True, reverse=True)]
        expected = sort(chain(*results), reverse=True)
        expected = [rid for sortkey, rid, getitem in expected]
        self.assertEqual(merged_rids, expected)
 def test_no_filter_or_sort(self):
     catalogs, mergeResults = self._make_many()
     results = [cat.searchResults(
                dict(number=True), _merge=0) for cat in catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=False, reverse=False)]
     expected = [r.getRID() for r in chain(*results)]
     self.assertEqual(self._sort(merged_rids), self._sort(expected))
Ejemplo n.º 8
0
 def test_no_filter_or_sort(self):
     catalogs, mergeResults = self._make_many()
     results = [cat.searchResults(
                dict(number=True), _merge=0) for cat in catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=False, reverse=False)]
     expected = [r.getRID() for r in chain(*results)]
     self.assertEqual(self._sort(merged_rids), self._sort(expected))
Ejemplo n.º 9
0
 def test_scored(self):
     catalogs, mergeResults = self._make_many()
     results = [cat.searchResults(title='4 or 5 or 6', _merge=0)
                for cat in catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=True, reverse=False)]
     expected = self._sort(chain(*results))
     expected = [rid for sortkey, (nscore, score, rid), getitem in expected]
     self.assertEqual(merged_rids, expected)
Ejemplo n.º 10
0
    def testSmallIndexSort(self):
        # Test that small index sort optimization is not used for merging
        from Products.ZCatalog.Catalog import mergeResults

        results = [cat.searchResults(dict(number=True, sort_on="big"), _merge=0) for cat in self.catalogs]
        merged_rids = [r.getRID() for r in mergeResults(results, has_sort_keys=True, reverse=False)]
        expected = sort(chain(*results))
        expected = [rid for sortkey, rid, getitem in expected]
        self.assertEqual(merged_rids, expected)
Ejemplo n.º 11
0
 def testLimitSort(self):
     from Products.ZCatalog.Catalog import mergeResults
     results = [cat.searchResults(sort_on='num', sort_limit=2, _merge=0)
                for cat in self.catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=True, reverse=False)]
     expected = sort(chain(*results))
     expected = [rid for sortkey, rid, getitem in expected]
     self.assertEqual(merged_rids, expected)
 def test_scored(self):
     catalogs, mergeResults = self._make_many()
     results = [cat.searchResults(title='4 or 5 or 6', _merge=0)
                for cat in catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=True, reverse=False)]
     expected = self._sort(chain(*results))
     expected = [rid for sortkey, (nscore, score, rid), getitem in expected]
     self.assertEqual(merged_rids, expected)
Ejemplo n.º 13
0
 def testScored(self):
     from Products.ZCatalog.Catalog import mergeResults
     results = [cat.searchResults(title='4 or 5 or 6', _merge=0)
                for cat in self.catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=True, reverse=False)]
     expected = sort(chain(*results))
     expected = [rid for sortkey, (nscore, score, rid), getitem in expected]
     self.assertEqual(merged_rids, expected)
Ejemplo n.º 14
0
 def testSortReverse(self):
     from Products.ZCatalog.Catalog import mergeResults
     results = [cat.searchResults(
                dict(number=True, sort_on='num'), _merge=0)
                for cat in self.catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=True, reverse=True)]
     expected = sort(chain(*results), reverse=True)
     expected = [rid for sortkey, rid, getitem in expected]
     self.assertEqual(merged_rids, expected)
Ejemplo n.º 15
0
 def test_sort_reverse(self):
     catalogs, mergeResults = self._make_many()
     results = [cat.searchResults(
                dict(number=True, sort_on='num'), _merge=0)
                for cat in catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=True, reverse=True)]
     expected = self._sort(chain(*results), reverse=True)
     expected = [rid for sortkey, rid, getitem in expected]
     self.assertEqual(merged_rids, expected)
 def test_sort_reverse(self):
     catalogs, mergeResults = self._make_many()
     results = [cat.searchResults(
                dict(number=True, sort_on='num'), _merge=0)
                for cat in catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=True, reverse=True)]
     expected = self._sort(chain(*results), reverse=True)
     expected = [rid for sortkey, rid, getitem in expected]
     self.assertEqual(merged_rids, expected)
Ejemplo n.º 17
0
 def testSmallIndexSort(self):
     # Test that small index sort optimization is not used for merging
     from Products.ZCatalog.Catalog import mergeResults
     results = [cat.searchResults(
                dict(number=True, sort_on='big'), _merge=0)
                for cat in self.catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=True, reverse=False)]
     expected = sort(chain(*results))
     expected = [rid for sortkey, rid, getitem in expected]
     self.assertEqual(merged_rids, expected)
Ejemplo n.º 18
0
 def test_small_index_sort(self):
     # Test that small index sort optimization is not used for merging
     catalogs, mergeResults = self._make_many()
     results = [cat.searchResults(
                dict(number=True, sort_on='big'), _merge=0)
                for cat in catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=True, reverse=False)]
     expected = self._sort(chain(*results))
     expected = [rid for sortkey, rid, getitem in expected]
     self.assertEqual(merged_rids, expected)
 def test_small_index_sort(self):
     # Test that small index sort optimization is not used for merging
     catalogs, mergeResults = self._make_many()
     results = [cat.searchResults(
                dict(number=True, sort_on='big'), _merge=0)
                for cat in catalogs]
     merged_rids = [r.getRID() for r in mergeResults(
         results, has_sort_keys=True, reverse=False)]
     expected = self._sort(chain(*results))
     expected = [rid for sortkey, rid, getitem in expected]
     self.assertEqual(merged_rids, expected)