public function up(\Eccube\Entity\Category $Category)
{
$em = $this->getEntityManager();
$em->getConnection()->beginTransaction();
try {
$rank = $Category->getRank();
$Parent = $Category->getParent();
if ($Parent) {
$CategoryUp = $this->createQueryBuilder('c')->where('c.rank > :rank AND c.Parent = :Parent')->setParameter('rank', $rank)->setParameter('Parent', $Parent)->orderBy('c.rank', 'ASC')->setMaxResults(1)->getQuery()->getSingleResult();
} else {
$CategoryUp = $this->createQueryBuilder('c')->where('c.rank > :rank AND c.Parent IS NULL')->setParameter('rank', $rank)->orderBy('c.rank', 'ASC')->setMaxResults(1)->getQuery()->getSingleResult();
}
$this_count = $Category->countBranches();
$up_count = $CategoryUp->countBranches();
$Category->calcChildrenRank($em, $up_count);
$CategoryUp->calcChildrenRank($em, $this_count * -1);
$em->flush();
$em->getConnection()->commit();
} catch (\Exception $e) {
$em->getConnection()->rollback();
return false;
}
return true;
}